-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: vm scheduler #10
Conversation
5bdcb96
to
556168e
Compare
Signed-off-by: WoodenMaiden <[email protected]>
556168e
to
8c73b39
Compare
6e92726
to
dfffa79
Compare
|
||
if returnedCursor != 0 { | ||
// the current sweep did not find anything, we try again | ||
return s.LookForReadyInstance(functionId, returnedCursor) |
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.
Is there a reason why this is recursive?
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.
Basically in Redis, SCAN allows you to get keys matching a certain pattern just like KEYS would.
While KEYS locks the DB and scans everything in one shot, SCAN gets x keys and returns a cursor, you can then use the returned cursor to your next SCAN call to continue scanning until the returned cursor is 0.
This is why it is recursive, I can refactor it into interative if you want.
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.
Okay I understand
You don't need to put that in an iterative way but if could just add some comments in your code to say what you just explained it would be really nice
scheduler/scheduler.go
Outdated
|
||
|
||
// because while does not exists in these lands | ||
for ok, cursor := true, uint64(0) ; ok; ok = (cursor != 0) { |
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.
maybe using a for true { if (...) break }
would be more understandable ;)
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.
Yeah I don't understand this line, feels like it could be simpler.
scheduler/scheduler.go
Outdated
|
||
|
||
// because while does not exists in these lands | ||
for ok, cursor := true, uint64(0) ; ok; ok = (cursor != 0) { |
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.
Yeah I don't understand this line, feels like it could be simpler.
main.go
Outdated
} | ||
//Now inject the scheduler into the routes that need it! | ||
|
||
err := cronjob.AddFunc("0 */6 * * *", func() { s.FindAndDestroyUnsused() }) |
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.
Do we really need a library to do this ?
Sounds like it could be a loop with a sleep in a separate thread (using the go
keyword)
scheduler/scheduler.go
Outdated
return | ||
} | ||
|
||
func (s *Scheduler) FindAndDestroyUnsused() { |
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.
It would be good to have a comment explaining what this do
dfffa79
to
3977be1
Compare
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.
Look good to me
Still a bit complicated on some points but it's good and we will add comment next time we work on that part ;)
Resolves #9