Skip to content

Commit

Permalink
fix(timer): one timer job failed should not block anothers
Browse files Browse the repository at this point in the history
  • Loading branch information
yeehomfoo committed Apr 22, 2024
1 parent b05f17f commit ff4a6b8
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions d_timer/sql/timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ func (t *DBTimer) handleJobs(ctx context.Context) error {
if err := tx.Clauses(clause.Locking{Strength: "UPDATE", Options: "NOWAIT"}).Where(
"service = ? and next_time <= ? and status = ? and id = ?", t.service, time.Now(), TimerToRun, job.ID,
).First(&job).Error; err != nil {
t.logger.V(logger.LevelDebug).Info("lock job failed", "jobID", job.ID, "err", err)
t.logger.V(logger.LevelDebug).Info("lock timer job failed", "jobID", job.ID, "err", err)
// continue
return nil
}

if err := t.cb(ctx, job.Key, job.Cron, job.Payload); err != nil {
t.logger.Error(err, "timer callback failed")
t.logger.Error(err, "timer job callback failed", "jobID", job.ID)
}
if err := job.Next(); err != nil {
job.Close(err)
Expand All @@ -144,7 +144,9 @@ func (t *DBTimer) handleJobs(ctx context.Context) error {

return nil
}); err != nil {
return err
// 只可能在保存Job和提交事务时发生
t.logger.Error(err, "save timer job failed", "jobID", job.ID)
continue
}
}

Expand Down

0 comments on commit ff4a6b8

Please sign in to comment.