mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-15 12:14:17 +00:00
fix(cron): RunJob NULL-safe comparison and timezone persistence
- Use IS DISTINCT FROM instead of != for NULL handling in RunJob claim - Always apply patch TZ (empty = UTC default). Callers send full schedule
This commit is contained in:
1 parent
04dc34e32c
commit
8ba4bd7c4a
2 files changed
+4
-6
No files matched your search
@@ -244,11 +244,9 @@ func MergeCronSchedule(current CronSchedule, patch *CronSchedule) CronSchedule {
|
||||
} else if current.Kind == newKind {
|
||||
merged.Expr = current.Expr
|
||||
}
|
||||
if patch.TZ != "" {
|
||||
merged.TZ = patch.TZ
|
||||
} else if current.Kind == newKind {
|
||||
merged.TZ = current.TZ
|
||||
}
|
||||
// TZ: always use patch value. Empty = UTC (default).
|
||||
// Callers (UI, agent tool) send full schedule via spread, so empty is explicit.
|
||||
merged.TZ = patch.TZ
|
||||
case "every":
|
||||
if patch.EveryMS != nil {
|
||||
merged.EveryMS = patch.EveryMS
|
||||
|
||||
@@ -33,7 +33,7 @@ func (s *PGCronStore) RunJob(ctx context.Context, jobID string, force bool) (boo
|
||||
if parseErr != nil {
|
||||
return false, "", fmt.Errorf("invalid job id %q: %w", jobID, parseErr)
|
||||
}
|
||||
res, err := s.db.ExecContext(ctx, "UPDATE cron_jobs SET last_status = 'running', next_run_at = NULL, updated_at = $1 WHERE id = $2 AND last_status != 'running'", time.Now(), id)
|
||||
res, err := s.db.ExecContext(ctx, "UPDATE cron_jobs SET last_status = 'running', next_run_at = NULL, updated_at = $1 WHERE id = $2 AND last_status IS DISTINCT FROM 'running'", time.Now(), id)
|
||||
if err != nil {
|
||||
slog.Warn("cron: failed to claim job for forced run", "jobId", jobID, "error", err)
|
||||
return false, "", err
|
||||
|
||||
Reference in new issue
Block a user