Way to have a Service exit "gracefully"?
Closed this issue · 5 comments
Just started playing around with your excellent library today... so if I've missed something obvious with my question, apologies!
I'm looking for a "simple" way to have a Service
exit gracefully from its Serve
method without it prompting a restart (the Service would essentially be saying, "My work is done here, please don't try to run me anymore!"). I would expect this behavior to be equivalent to calling Remove
on its containing Supervisor
, but without the hassle of tracking the ServiceToken
, passing that and the Supervisor
into the Service
, etc. Or, if this is considered bad practice, I'd love to learn a little more about why that may be.
Thanks in advance!
Can you tell me more about the use case?
The first thing that comes to mind is "Don't use suture for that". I've actually never had a service in either Erlang or Go that should stop itself.
Sure... I'm basically thinking of multi-step or long running jobs that could encounter errors and would need to be retried/restarted, but after having reached whatever their termination condition is, just need to exit. Think of online games, where there are in-game events that have specified durations followed by complex point tallying and reward generations, actions with side-effects that may expire, or even just quite generically, a service that needs to gather data from numerous different sources, translate it, and store it somewhere else, then exit. There are certainly other libraries that arguably tackle some of these problems, but on the other hand, retrying on a "root" process after an exception is often all that's needed.
OK, I'm convinced. I've not been feeling terribly well lately and there's holiday activities about, so it may be a bit before I merge it in here, but you can use your local branch in the meantime confident that it will work its way upstream in the near term.
I may change the interface name, but I think the method itself is fine, so it should have no impact on your code.
Great, much appreciated! And by all means, don't hesitate to change any of the names, it won't be a problem for me to fix things up later (i.e. in case you change your mind on the method name too). 👍
Whoops, reversed the issue & PR number or something and the auto-close didn't happen.