move cron parse into feed.ShouldExecute
This commit is contained in:
@@ -2,9 +2,30 @@ package feeds
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/robfig/cron/v3"
|
||||
)
|
||||
|
||||
func (feed Feed) ShouldExecute() (bool, error) {
|
||||
schedule, err := cron.NewParser(
|
||||
cron.SecondOptional |
|
||||
cron.Minute |
|
||||
cron.Hour |
|
||||
cron.Dom |
|
||||
cron.Month |
|
||||
cron.Dow |
|
||||
cron.Descriptor,
|
||||
).Parse(feed.Version.Cron)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("illegal cron %q", feed.Version.Cron)
|
||||
}
|
||||
next := schedule.Next(feed.Execution.Executed)
|
||||
return time.Now().Before(next), nil
|
||||
}
|
||||
|
||||
func (feed Feed) Fetch(ctx context.Context) (Items, error) {
|
||||
return nil, io.EOF
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user