summaryrefslogtreecommitdiff
path: root/internal/scheduler/buckets.go
blob: 5fa242d19f530246b7692e8ce52f16c491aacfe9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package scheduler

import (
	"context"
	"log"
	"time"

	"task-dashboard/internal/config"
	"task-dashboard/internal/store"
)

// RunBucketCycleCheck ticks every interval, calling RunBucketCycles until
// ctx is cancelled. Mirrors RunRecurrenceCheck's shape -- errors are
// logged, not fatal, so one bad tick doesn't kill the loop.
func RunBucketCycleCheck(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.RunBucketCycles(config.Now())
			if err != nil {
				log.Printf("ERROR [BucketCycleCheck]: %v", err)
				continue
			}
			if n > 0 {
				log.Printf("BucketCycleCheck: activated %d item(s)", n)
			}
		}
	}
}