mirror of
https://github.com/idanoo/autobrr
synced 2025-07-22 16:29:12 +00:00
fix(scheduler): use time as opposed to cron fields (#390)
* fix(torznab): use time for interval. * flip Schedule to be duration based * typefix * Update service.go * clear err * pull err package * casting to the moon * enforce a minimum of 15m * lower minimum based on feedback from Unit3d
This commit is contained in:
parent
eefd1b576c
commit
bbfa5627aa
2 changed files with 9 additions and 15 deletions
|
@ -5,7 +5,6 @@ import (
|
|||
|
||||
"github.com/autobrr/autobrr/internal/logger"
|
||||
"github.com/autobrr/autobrr/internal/notification"
|
||||
"github.com/autobrr/autobrr/pkg/errors"
|
||||
|
||||
"github.com/robfig/cron/v3"
|
||||
"github.com/rs/zerolog"
|
||||
|
@ -14,7 +13,7 @@ import (
|
|||
type Service interface {
|
||||
Start()
|
||||
Stop()
|
||||
AddJob(job cron.Job, interval string, identifier string) (int, error)
|
||||
AddJob(job cron.Job, interval time.Duration, identifier string) (int, error)
|
||||
RemoveJobByID(id cron.EntryID) error
|
||||
RemoveJobByIdentifier(id string) error
|
||||
}
|
||||
|
@ -63,7 +62,7 @@ func (s *service) addAppJobs() {
|
|||
lastCheckVersion: "",
|
||||
}
|
||||
|
||||
s.AddJob(checkUpdates, "2 */6 * * *", "app-check-updates")
|
||||
s.AddJob(checkUpdates, time.Duration(36 * time.Hour), "app-check-updates")
|
||||
}
|
||||
|
||||
func (s *service) Stop() {
|
||||
|
@ -72,14 +71,11 @@ func (s *service) Stop() {
|
|||
return
|
||||
}
|
||||
|
||||
func (s *service) AddJob(job cron.Job, interval string, identifier string) (int, error) {
|
||||
func (s *service) AddJob(job cron.Job, interval time.Duration, identifier string) (int, error) {
|
||||
|
||||
id, err := s.cron.AddJob(interval, cron.NewChain(
|
||||
id := s.cron.Schedule(cron.Every(interval), cron.NewChain(
|
||||
cron.SkipIfStillRunning(cron.DiscardLogger)).Then(job),
|
||||
)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "scheduler: add job failed")
|
||||
}
|
||||
|
||||
s.log.Debug().Msgf("scheduler.AddJob: job successfully added: %v", id)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue