-
Notifications
You must be signed in to change notification settings - Fork 335
Open
Description
Bug
PGCronStore.EnableJob() sets enabled = true but does not update next_run_at. Since GetDueJobs() filters by next_run_at <= now, the job never fires after being re-enabled via the UI toggle (cron.toggle RPC).
Root Cause
// cron_crud.go — current code
func (s *PGCronStore) EnableJob(jobID string, enabled bool) error {
_, err = s.db.Exec("UPDATE cron_jobs SET enabled = $1, updated_at = $2 WHERE id = $3", enabled, time.Now(), id)
// ...
}When enabling: next_run_at stays NULL (cleared when disabled), so GetDueJobs skips it forever. recomputeStaleJobs() only runs at startup, not after UI toggle.
When disabling: next_run_at is not cleared, so the scheduler may still pick it up briefly.
Expected Behavior
- Enable: read schedule fields from DB, call
computeNextRun(), setnext_run_at - Disable: set
next_run_at = NULLimmediately
Suggested Fix
func (s *PGCronStore) EnableJob(jobID string, enabled bool) error {
if !enabled {
// Clear next_run_at so GetDueJobs skips immediately
s.db.Exec("UPDATE cron_jobs SET enabled = false, next_run_at = NULL, updated_at = $1 WHERE id = $2", now, id)
s.cacheLoaded = false
return nil
}
// Enable: read schedule, compute next_run_at
row := s.db.QueryRow(`SELECT schedule_kind, cron_expression, run_at, timezone, interval_ms FROM cron_jobs WHERE id = $1`, id)
// ... scan into CronSchedule ...
next := computeNextRun(&schedule, now, defaultTZ)
s.db.Exec("UPDATE cron_jobs SET enabled = true, next_run_at = $1, updated_at = $2 WHERE id = $3", next, now, id)
s.cacheLoaded = false
return nil
}Steps to Reproduce
- Create a cron job (e.g.,
0 7 * * *) - Disable it via UI →
cron.toggleRPC - Re-enable it via UI →
cron.toggleRPC - Wait for scheduled time — job never fires
- Check DB:
next_run_atisNULLdespiteenabled = true
Environment
- GoClaw v1.74.1
- PostgreSQL-backed cron store (
PGCronStore)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels