Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] - ErrAtTimeNotSupported when trying to Update/reschedule Job #499

Closed
calvinmclean opened this issue May 27, 2023 · 4 comments · Fixed by #502
Closed

[BUG] - ErrAtTimeNotSupported when trying to Update/reschedule Job #499

calvinmclean opened this issue May 27, 2023 · 4 comments · Fixed by #502
Labels
bug Something isn't working

Comments

@calvinmclean
Copy link

Describe the bug

When attempting to reschedule a Job originally scheduled with Every(time.Duration) by setting a new StartAt time (to delay 24 hours), ErrAtTimeNotSupported is returned. It's unexpected because I used StartAt on the original scheduling so the re-schedule isn't doing anything different.

I'm not 100% sure this is a bug or intentional behavior, but I started getting this error after updating from v1.18.1.

To Reproduce

Reproducible with this test:

func TestGoCron(t *testing.T) {
	s := gocron.NewScheduler(time.Local)
	s.StartAsync()
	defer s.Stop()

	startDate, err := time.Parse(time.RFC3339, "2022-04-23T22:00:00-07:00")
	assert.NoError(t, err)

	_, err = s.
		Every(24*time.Hour).
		StartAt(startDate).
		Tag("TAG_ID").
		Do(fmt.Println, "Hello!")
	assert.NoError(t, err)

	sort.Sort(s)
	jobs, err := s.FindJobsByTag("TAG_ID")
	assert.NoError(t, err)
	assert.Len(t, jobs, 1)

	nextRun := jobs[0].NextRun()
	newNextRun := nextRun.Add(24 * time.Hour)

	newJob, err := s.Job(jobs[0]).
		StartAt(newNextRun).
		Update()
	assert.NoError(t, err)
	if newJob != nil {
		assert.Equal(t, newNextRun, newJob.NextRun())
	}
}

Version

v1.28.0

Expected behavior

Expectations are shown in the above test code: no error and job is rescheduled for 24 hours in the future.

Additional context

The error is coming from here.
In both the original scheduling and re-scheduling, jobUnit is duration. In original schedule, job.getAtTime(jobLastRun) is 0, so there is no error. When rescheduling, this is a non-zero value and it errors.

@calvinmclean calvinmclean added the bug Something isn't working label May 27, 2023
@calvinmclean
Copy link
Author

I just tried changing Every(24 * time.Hour) to Every(1).Day() and now it works as expected, so I at least have a workaround.
However, if you review this and think it sounds like a real bug, I can create a PR to fix it if you are able to give a little background info on what is the issue :)

@JohnRoesler
Copy link
Contributor

I believe it’s a bug. I’ll take a deeper look later this week. A pr would of course be appreciated!

@JohnRoesler
Copy link
Contributor

I found the issue. I'll have a PR up this week

@calvinmclean
Copy link
Author

I found the issue. I'll have a PR up this week

Thanks for the quick fix! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants