-
Notifications
You must be signed in to change notification settings - Fork 343
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
add TimerWheel #8
base: master
Are you sure you want to change the base?
Conversation
@flier This isn't working. The interface you implemented is structured much better than the rest of this project and on all accounts the algorithm you're attempting to implement is way more efficient than what is currently implemented. But, when I try to schedule something simple like this your implementation clearly isn't working. Please let me know if you fix it. secondCount := 1
scheduler.Every(1).Second().Do(func() {
log.Printf("%d second", secondCount)
secondCount++
})
scheduler.Every(1).Minute().Do(func() {
log.Printf("%d minute", secondCount/60)
})
scheduler.Every(1).Hour().Do(func() {
log.Printf("%d hour", secondCount/(60*60))
}) |
* Scheduler Changes * refactored the Scheduler into an interface so that we can potentially swap out implementations (see pull #8) * changed `Scheduler.Start() chan bool` to `Scheduler.Start()` * added `Scheduler.IsRunning()` and `Scheduler.Stop()` to check if the scheduler is running and to stop it from ronning, respectively * Renamed `Scheduler.RunAllwithDelay` to `Scheduler.RunAllWithDelay` to match standard syntax * Added runPending(time.Time) in order to synchronize all rin loops on the ticker time * Added a mutex lock for concurrency support * Added default location support at the scheduler lever with `Scheduler.Location(...)` * Job Changes * moved all initialization logic into `init(time.Time)` and `isInit() bool` for code clarity and testability * changed `shouldRun() bool` to `shouldRun(time.Time) bool` in order to accept a passed in time from the current ticker iteration, for run loop synchronicity * rewrote `At(...)` to parse into a time.Duration * added support for intervals greater than 1 for days of the week * added `Weekday(time.Weekday)` and made `Sunday()`, `Monday()`, ... alises of it * added `time.Location` support on a per job basis * standardized the comment structure and added some better godoc documentation * added support for intervals greater than 1 for any weekday with a strongly defined edge case behavior added to the docs * fixed #4, by removing the panics in Day, Hour, Minute, Second, etc * added basic test structure * removed the global `ChangeLoc(...)` method. In favor of setting the default via the scheduler and on a per job baisis * finish writing tests and make sure they all pass * write examples * update ReadMe.md
For the TM scheduler, we need start the scheduler first https://gist.github.com/flier/749b82879b48dbc739eb On the other hand, I suggest we could split the Scheduler interface to two https://gist.github.com/flier/7823f7ef02eff0058a7f What's your opinion? Mark Salpeter [email protected]于2015年12月21日周一 上午6:38写道:
|
I actually don't see the use cases for RunAll/RunAllWithDelay, but couldn't those be implemented by iterating over the backing slice of jobs? Is there a good resource for the timer wheel algorithm somewhere so that I can better understand the issue? Is it just a matter of keeping the job slice in sort order at all times? |
In fact, I implement the time wheel scheduler for some internal networking Yes, we can locking and iterating all the slots one by one, if you believe Mark Salpeter [email protected]于2015年12月22日周二 上午12:52写道:
|
any progress on that? sounds very promising. |
After(interval uint64) *Job
func (j *Job) Milliseconds() (job *Job)