feat: add daily cron to apply scheduled default hours changes

Add ApplyScheduledDefaultHours which checks default_hours_scheduled_changes at midnight, bulk-updates working_hours with staged values, and inserts an admin_notification. Register as the 'apply-default-hours' job in the scheduler (daily at 00:05).
This commit is contained in:
2026-08-22 00:34:49 +01:00
parent d0f233ae70
commit 70613497b4
3 changed files with 112 additions and 5 deletions
+10
View File
@@ -133,6 +133,16 @@ func RegisterAll(s *Scheduler) {
Handler: scheduling.CleanupOldNameHistory,
})
// === STAGED HOURS CHANGE ===
s.Register(Job{
Name: "apply-default-hours",
Schedule: "5 0 * * *", // Daily at 00:05 — after midnight to avoid race
Timeout: 30 * time.Second,
Concurrency: 1,
Handler: scheduling.ApplyScheduledDefaultHours,
})
// === BUSINESS LOGIC JOBS ===
s.Register(Job{
+3 -5
View File
@@ -407,17 +407,14 @@ func TestColoredRows_Reset(t *testing.T) {
// RegisterAll Tests
// ============================================================
// TestRegisterAll_RegistersExpectedJobs verifies RegisterAll registers exactly 19 jobs
// with all required fields populated (non-empty Name, non-empty Schedule, non-nil
// Handler, positive Timeout).
func TestRegisterAll_RegistersExpectedJobs(t *testing.T) {
t.Parallel()
s := New()
RegisterAll(s)
if got := len(s.registry); got != 19 {
t.Fatalf("RegisterAll() registered %d jobs, want 19", got)
if got := len(s.registry); got != 20 {
t.Fatalf("RegisterAll() registered %d jobs, want 20", got)
}
registered := make(map[string]Job, len(s.registry))
@@ -490,6 +487,7 @@ func expectedJobNames() map[string]bool {
"transition-discount-campaigns": true,
"cleanup-verification-codes": true,
"cleanup-refresh-tokens": true,
"apply-default-hours": true,
}
}