move cron parse into feed.ShouldExecute

This commit is contained in:
Bel LaPointe
2025-04-27 12:04:11 -06:00
parent a097814a62
commit ab396d1833
3 changed files with 55 additions and 13 deletions

View File

@@ -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
}