-
-
Notifications
You must be signed in to change notification settings - Fork 305
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: schedules jobs with time.AfterFunc() #99
Conversation
j.setStartsImmediately(false) | ||
} | ||
if !j.shouldRun() { | ||
if j.getRemoveAfterLastRun() { // TODO: this method seems unnecessary as we could always remove after the run cout has expired. Maybe remove this in the future? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking awesome! just some races to clean up
@JohnRoesler thank you so much for the feedback and cleaning up the data race issues! Edit: I just made one more commit as I mistakenly forgot to listen to |
scheduler.go
Outdated
for _, job := range s.runnableJobs() { | ||
s.runAndReschedule(job) // we should handle this error somehow | ||
func (s *Scheduler) run(job *Job) { | ||
if !s.running { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JohnRoesler also, do you think this might help with that issue that we talked earlier on slack?
What does this do?
Main change: scheduler now uses
time.AfterFunc
from the standardtime
package to schedule jobs instead of manually sorting and looping through all jobs (yes, finally!)This brings us:
nextRun
or even our job slice for our run logic (they may still be useful for logging or getting meta info about a job or the scheduler, so they're not removed here)Unfortunately, after doing this refactor and separating the logic correctly, some tests broke, which made this pr a bit larger than what it needed to be. Fortunately, these failures actually brought minor errors to attention; I fixed them in here, so here's a list of what's different:
.Close()
without listening to the channel returned by.StartAsync()
would freeze the application; fixed by makingstopChan
a buffered channel: now the application doesn't freeze up anymorego job.Run()
. This method not only calls the job function but also updates the run counter, which fails to remove jobs that start immediately (this passed our tests because all tests used.At()
). This has been fixed, and now we first update our run counter and only later call the job's function; thus it's launch is actually the last thing to be done in the execution chainTestExecutionSecond
toTestImmediateExecution
, as this is what was actually being tested hereTestAtFuture
to uset.Run()
and the news.start()
methodTestRunJobsWithLimit
to tests cases with immediate executionList any changes that modify/break current functionality
None
Have you included tests for your changes?
Yes
Notes
I did my tests manually here, but if possible guys, take a look at some running examples to also check if they are working correctly.
A simple example of manual testing function that can be called from any testing file: