asynq: [QUESTION] i think set stop in run function is not a good idea
https://github.com/hibiken/asynq/blob/master/background.go#L253
normally, packages has two methods, Run and Stop, so i can cleanup other resources before or after Stop(),
another scene is that user will run multipe backgroud server in main(), like kafka consumer
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (10 by maintainers)
Closed via #135
@zsiec Awesome to hear your feedback! Thank you.
I’m currently drafting a PR for this change, which includes a few breaking changes (I’ll make sure to document the upgrade paths in CHANGELOG for those who are on the current version).
+1 to exporting these. Some weeks ago I forked and exposed start/stop myself but have now stumbled on this thread and would be happy to remove my fork and use this once it’s ready!
My current implementation (importing my fork) handles the syscall termination signals for the workers as I was already handling them for other things before using asynq and it’s helpful to me to have my graceful shutdown logic collocated. It was also trivial to implement a shutdown timeout external to this library.
Thanks for your work on this very usable project, looking forward to seeing these updates!
It’s fine. breaking change needs to thinking more and more.
Looking forward to your final design.
Yep, just exporting just
StartandStopmakes sense to me (choseStopbecause of the symmetry withStart).So effectively, if user uses
StartandStopinstead ofRunthey don’t get some nice signal handling but I guess that’s okay. If we get feature request to exportQuiet(i.e. stop processing new tasks), maybe we’ll add that later.I’ll get started on making these changes and ping you in the PR 👍
I see. I can see why this could be confusing. Let me try to explain.
First Question
Asynq took a lot of ideas from Sidekiq and they use OS signals to handle graceful shutdown (video).
Currently, when you start background workers with
bg.Runit waits for signals. Asynq handles TERM, INT, and TSTP signals. If you send TSTP signal to the process, asynq will stop processing new tasks but doesn’t exit. This is documented in Sidekiq here.If you send TERM or INT signal to the process, asynq will wait for few seconds to let active workers finish its tasks but if they don’t finish within that timeout, asynq will push the tasks back to Redis and exit the process. This is documented in Sidekiq here.
My intention was to name the first operation
Stopand the second oneShutdown. But I can see whyStopis a bit confusing. Looking at sidekiq doc, maybe we can name itbg.Quiet()?Does that makes sense?
Second Question
I agree with the
Concurrencyper Handler (i.e.Concurrencyper task type). For example, if you have a task to use third-party API and if they have a limit on how many concurrent API calls they can handle, this is definitely useful. Am I understanding you correctly here?I’m not sure if we can add an option to specify Queues per Handler though.
gocraft/workhas a different design in that they have one-to-one mapping between job-type and queue. Asynq’s design is similar to sidekiq. It allows for multipe queues with different priority but any task can be put on any queue. So I’m not sure if we can create Queue option for a Handler. (please let me know if I’m not understanding your point correctly).the idea from
net/httpseems good, but the functions nameNewServeris confused.If i did not read the doc, i would think it’s a server to receive request and produce a job. other names likeServe,NewServeMuxalso confusedHandler is part of Config: i prefer the api likegin