Files
creator-hub/internal/creator/scheduler.go
T

40 lines
881 B
Go

package creator
import "time"
type ScheduleKind string
const (
ScheduleNewWorks ScheduleKind = "new_works"
ScheduleComments ScheduleKind = "comments"
ScheduleMetrics ScheduleKind = "metrics"
)
func IsDue(lastCompleted, now time.Time, interval time.Duration) bool {
if now.IsZero() || interval <= 0 {
return false
}
if lastCompleted.IsZero() {
return true
}
return !now.UTC().Before(lastCompleted.UTC().Add(interval))
}
func NextFixedRun(lastCompleted, now time.Time, interval time.Duration) time.Time {
if now.IsZero() || interval <= 0 {
return time.Time{}
}
if lastCompleted.IsZero() {
return now.UTC()
}
next := lastCompleted.UTC().Add(interval)
for !next.After(now.UTC()) {
next = next.Add(interval)
}
return next
}
func MetricDue(work Work, now time.Time) bool {
return work.NextMetricAt != nil && !now.UTC().Before(work.NextMetricAt.UTC())
}