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:
Kyle Sanderson 2022-08-01 14:24:14 -07:00 committed by GitHub
parent eefd1b576c
commit bbfa5627aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 15 deletions

View file

@ -2,7 +2,6 @@ package feed
import (
"context"
"fmt"
"github.com/autobrr/autobrr/internal/domain"
"github.com/autobrr/autobrr/internal/logger"
@ -13,6 +12,7 @@ import (
"github.com/dcarbone/zadapters/zstdlog"
"github.com/rs/zerolog"
"time"
)
type Service interface {
@ -34,7 +34,7 @@ type feedInstance struct {
URL string
ApiKey string
Implementation string
CronSchedule string
CronSchedule time.Duration
}
type service struct {
@ -274,15 +274,13 @@ func (s *service) startJob(f domain.Feed) error {
}
// cron schedule to run every X minutes
schedule := fmt.Sprintf("*/%d * * * *", f.Interval)
fi := feedInstance{
Name: f.Name,
IndexerIdentifier: f.Indexer,
Implementation: f.Type,
URL: f.URL,
ApiKey: f.ApiKey,
CronSchedule: schedule,
CronSchedule: time.Duration(f.Interval) * time.Minute,
}
switch fi.Implementation {
@ -302,8 +300,8 @@ func (s *service) addTorznabJob(f feedInstance) error {
if f.URL == "" {
return errors.New("torznab feed requires URL")
}
if f.CronSchedule == "" {
f.CronSchedule = "*/15 * * * *"
if f.CronSchedule < time.Duration(5 * time.Minute) {
f.CronSchedule = time.Duration(15 * time.Minute)
}
// setup logger