refactor(api): update scheduler to match new cron lib API (#3157)
parent
8e922dbfc6
commit
baa64ca927
|
@ -13,13 +13,14 @@ type JobScheduler struct {
|
||||||
// NewJobScheduler initializes a new service
|
// NewJobScheduler initializes a new service
|
||||||
func NewJobScheduler() *JobScheduler {
|
func NewJobScheduler() *JobScheduler {
|
||||||
return &JobScheduler{
|
return &JobScheduler{
|
||||||
cron: cron.New(),
|
cron: cron.New(cron.WithSeconds()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScheduleJob schedules the execution of a job via a runner
|
// ScheduleJob schedules the execution of a job via a runner
|
||||||
func (scheduler *JobScheduler) ScheduleJob(runner portainer.JobRunner) error {
|
func (scheduler *JobScheduler) ScheduleJob(runner portainer.JobRunner) error {
|
||||||
return scheduler.cron.AddJob(runner.GetSchedule().CronExpression, runner)
|
_, err := scheduler.cron.AddJob(runner.GetSchedule().CronExpression, runner)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateSystemJobSchedule updates the first occurence of the specified
|
// UpdateSystemJobSchedule updates the first occurence of the specified
|
||||||
|
@ -35,7 +36,7 @@ func (scheduler *JobScheduler) UpdateSystemJobSchedule(jobType portainer.JobType
|
||||||
|
|
||||||
for _, entry := range cronEntries {
|
for _, entry := range cronEntries {
|
||||||
if entry.Job.(portainer.JobRunner).GetSchedule().JobType == jobType {
|
if entry.Job.(portainer.JobRunner).GetSchedule().JobType == jobType {
|
||||||
err := newCron.AddJob(newCronExpression, entry.Job)
|
_, err := newCron.AddJob(newCronExpression, entry.Job)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -69,7 +70,7 @@ func (scheduler *JobScheduler) UpdateJobSchedule(runner portainer.JobRunner) err
|
||||||
jobRunner = entry.Job
|
jobRunner = entry.Job
|
||||||
}
|
}
|
||||||
|
|
||||||
err := newCron.AddJob(runner.GetSchedule().CronExpression, jobRunner)
|
_, err := newCron.AddJob(runner.GetSchedule().CronExpression, jobRunner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue