mirror of
https://github.com/portainer/portainer.git
synced 2025-07-23 07:19:41 +02:00
refactor(stack): stack build process backend only [EE-4342] (#7750)
This commit is contained in:
parent
83a1ce9d2a
commit
e9de484c3e
65 changed files with 2270 additions and 942 deletions
34
api/stacks/deployments/scheduled.go
Normal file
34
api/stacks/deployments/scheduled.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package deployments
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/portainer/portainer/api/dataservices"
|
||||
"github.com/portainer/portainer/api/scheduler"
|
||||
)
|
||||
|
||||
func StartStackSchedules(scheduler *scheduler.Scheduler, stackdeployer StackDeployer, datastore dataservices.DataStore, gitService portainer.GitService) error {
|
||||
stacks, err := datastore.Stack().RefreshableStacks()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to fetch refreshable stacks")
|
||||
}
|
||||
|
||||
for _, stack := range stacks {
|
||||
d, err := time.ParseDuration(stack.AutoUpdate.Interval)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Unable to parse auto update interval")
|
||||
}
|
||||
stackID := stack.ID // to be captured by the scheduled function
|
||||
jobID := scheduler.StartJobEvery(d, func() error {
|
||||
return RedeployWhenChanged(stackID, stackdeployer, datastore, gitService)
|
||||
})
|
||||
|
||||
stack.AutoUpdate.JobID = jobID
|
||||
if err := datastore.Stack().UpdateStack(stack.ID, &stack); err != nil {
|
||||
return errors.Wrap(err, "failed to update stack job id")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue