summaryrefslogtreecommitdiff
path: root/internal/scheduler/recurrence.go
diff options
context:
space:
mode:
authorPeter Stone <thepeterstone@gmail.com>2026-07-14 20:30:16 +0000
committerPeter Stone <thepeterstone@gmail.com>2026-07-16 02:44:32 +0000
commitba5205213f6f1995ca4e64b08925bcc6c48b8211 (patch)
tree7d8fbaa6c2007d8582252d7b1e417ce003566caa /internal/scheduler/recurrence.go
parent550ffde0d8b71be96a4d21d7c07b718f367c2c48 (diff)
feat(tasks): add periodic due-date check for recurring tasks
A recurring task's successor now also gets created once its due date passes, independent of completion -- an ignored/overdue recurring task no longer blocks the next occurrence from appearing. Runs every 15 minutes via a new goroutine in main.go, cancelled on shutdown.
Diffstat (limited to 'internal/scheduler/recurrence.go')
-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)
+ }
+ }
+ }
+}