summaryrefslogtreecommitdiff
path: root/internal/scheduler
diff options
context:
space:
mode:
Diffstat (limited to 'internal/scheduler')
-rw-r--r--internal/scheduler/recurrence.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/internal/scheduler/recurrence.go b/internal/scheduler/recurrence.go
new file mode 100644
index 0000000..3d48d8f
--- /dev/null
+++ b/internal/scheduler/recurrence.go
@@ -0,0 +1,33 @@
+package scheduler
+
+import (
+ "context"
+ "log"
+ "time"
+
+ "task-dashboard/internal/config"
+ "task-dashboard/internal/store"
+)
+
+// RunRecurrenceCheck ticks every interval, calling AdvanceDueRecurringTasks
+// until ctx is cancelled. Errors are logged, not fatal -- one bad tick
+// shouldn't kill the loop; the next tick tries again.
+func RunRecurrenceCheck(ctx context.Context, s *store.Store, interval time.Duration) {
+ ticker := time.NewTicker(interval)
+ defer ticker.Stop()
+ for {
+ select {
+ case <-ctx.Done():
+ return
+ case <-ticker.C:
+ n, err := s.AdvanceDueRecurringTasks(config.Now())
+ if err != nil {
+ log.Printf("ERROR [RecurrenceCheck]: %v", err)
+ continue
+ }
+ if n > 0 {
+ log.Printf("RecurrenceCheck: created %d next iteration(s)", n)
+ }
+ }
+ }
+}