gocron: [BUG] - Nightly job run twice

Describe the bug

It seems this long standing issue (see #52, #132, #159, and #601) is still unresolved.

I have configured a daily job running at 3:00, which processes a batch of entities relevant to my domain. The job completes in around 170ms:

_, _ = scheduler.NewJob(
		gocron.DailyJob(1, gocron.NewAtTimes(gocron.NewAtTime(3, 0, 0))),
		gocron.NewTask(task.MyTask, myParam1, myParam2),
		gocron.WithEventListeners(
			gocron.AfterJobRunsWithError(func(jobID uuid.UUID, jobName string, err error) {
				log.Printf("failed my task: %v", err)
			})),
)

but this occurred last night:

2024-10-22T03:00:00.245294425Z stderr F 2024/10/22 03:00:00 processing thing with ID 59e50053-0d33-4729-9732-9e69ade399a2
...
2024-10-22T03:00:00.414909773Z stderr F 2024/10/22 03:00:00 processing thing with ID 59e50053-0d33-4729-9732-9e69ade399a2

Version

  • gocron: 2.12.1

Expected behavior

The task should be run only once.

Additional context

I have tested the scheduler behavior locally and the NextRuns method of the job returned what is expected.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 16 (8 by maintainers)

Most upvoted comments

EDIT: Removing my comment since in my case it was an implementation error, sorry guys

@wandering-tales thanks for letting me know! Really glad it wasn’t the library, because I was worried about the potential resurgence of this issue from v1 that I thought the v2 design completely solved, which it did 😓 !

I’d gladly get a beer with you if we’re ever in the same place in this world 😄 🍻

@JohnRoesler Sorry for not reaching out sooner.

tl;dr I have finally identified the (silly) reason of the double scheduling and it’s not due to a bug in the gocron library.

After a deeper investigation, I have discovered the microservice where the scheduler is running had a replica and, obviously, my job was run twice. The issue has been finally solved using a distributed locker, in this specific case gocron-gorm-lock.

I apologize for all the effort you put in this issue, and your commitment on this project in general. I could have started this investigation before even opening this issue… I owe you a couple of beers 🍻 😁 !!

Thanks @wandering-tales! Let me know the results. Sorry for the confusion on that. Fair to expect a release candidate’s changes to be in the actual release version of the same number. In this case, I had some other changes folks wanted to see, so I went ahead and released those without this change.

@JohnRoesler My bad. I had wrongly assumed 2.14.2 already included changes in 2.14.2-rc1. I’ll downgrade it to the latter.