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

refact: rewriting scheduler logic #54

Merged
merged 15 commits into from
Sep 8, 2020
Merged

Conversation

Streppel
Copy link
Member

@Streppel Streppel commented Aug 29, 2020

What does this do?

Time scheduling was spread between job registration and actual schedule calculation, which was confusing and made testing difficult. As a matter of fact, our weekdays logic wasn't working for some edge cases and we probably had some bugs out on .Month() calculation too, although I didn't check it explicitly.

This PR rewrites our next-run scheduling logic and cover it with different tests use cases, taking in consideration weekday schedules, weekdays schedules starting immediately and exact-time schedules.

Sorry for it being big. Most of the new lines are tests cases.

Which issue(s) does this PR fix/relate to?

This might fix #52. I cannot actually say this fixes it since I was not able to reproduce it, but nevertheless this PR fixes weekday logic.

List any changes that modify/break current functionality

None

Have you included tests for your changes?

Lots of, but might have missed something. Please bring it up if you can think of anything.

@@ -306,23 +365,6 @@ func (s *Scheduler) Do(jobFun interface{}, params ...interface{}) (*Job, error)
}
}

if !j.startsImmediately {

if j.lastRun == s.time.Unix(0, 0) {
Copy link
Member Author

@Streppel Streppel Aug 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was a workaround that had impact on the job scheduling logic and got removed

Copy link
Member

@arjunmahishi arjunmahishi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have looked at the code so far. Haven't seen the tests yet.

job.go Outdated Show resolved Hide resolved
timeHelper.go Show resolved Hide resolved
scheduler_test.go Outdated Show resolved Hide resolved
scheduler_test.go Outdated Show resolved Hide resolved
scheduler_test.go Outdated Show resolved Hide resolved
Co-authored-by: John Roesler <[email protected]>
job.go Outdated Show resolved Hide resolved
job.go Outdated Show resolved Hide resolved
@Streppel
Copy link
Member Author

Streppel commented Sep 8, 2020

@arjunmahishi @JohnRoesler cleaned up tests and fixed monthly issues, good to go now :-) there are tests missing (startImmediately reschedule etc) but we didn't have a strong test suite for these before anyway, so what do you think about leaving these tests for a future PR?

Our schedule method is now much more assertive, intelligent and readable IMO. Download the branch and let me know what you think.

Copy link
Member

@arjunmahishi arjunmahishi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Streppel Streppel merged commit 04be48f into master Sep 8, 2020
@github-actions github-actions bot deleted the fix/weekdays_scheduling branch September 8, 2020 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] - Runs task twice
3 participants