Closed itsdalmo closed 6 years ago
@lox: I've started some work here: https://github.com/itsdalmo/lifecycled/commits/add-happy-path
So far I've added 3 quick commits:
These commits lay the groundwork for the "happy path" discussed above. Note that they are very rough and will need some polish before I can submit a PR, should you want it. Let me know!
Awesome, will check them out, absolutely submit a PR!
Closed by #45.
Ref my comment here: https://github.com/buildkite/lifecycled/pull/40#issuecomment-418678672
I'd like to flesh out how I'd like to fix this, since I suspect it'd involve some refactoring that you may/may not be on board with and would possibly make the PR hard to review as a whole. So it's probably a good idea to flesh out the overall "plan" before I start work:
daemon.Start()
to return acompleteFunc
which is what actually sends theCompleteLifecycleAction
request and can be invoked frommain.go
. The reason for this is that we'd like the queue to be cleaned up before the interrupt signal is received (giving us more time for retries etc).daemon.Start()
will need to be rewritten to support a "happy path" which does not require a signal in order to shut down. While I'm at it/since the two go-routines indaemon.Start()
(i.e.go func()...
) essentially do the same thing, they invoke the handler if a termination notice is received. With some refactoring I believe this could be simplified a bit and hopefully become easier to reason about "the happy path":(PS: Wrote the code above in the issue so take it as psuedo-code 😎)
pollSpotTermination
is made into a private method ofDaemon
.handleMessage
,queue.Receive
and this go-routine are combined into one function:pollTerminationNotice
(also a private method ofDaemon
). The new function just becomes a loop which polls for new messages, unmarshals and filters the messages, and only passes messages that should be acted on over the channel.type
so we can use the same channel for bothspotTermination
andterminationNotice
, and then use a simpler loop insidedaemon.Start
.If you'd consider accepting the changes above, I'll be happy to submit a PR that we can discuss further!