Skip to content

Keep queue running during lifetime of application #470

Answered by brandur
vsoch asked this question in Q&A
Discussion options

You must be logged in to vote

@vsoch Yep, all you need to do is to call Client.Start and the River client will run until one of the following conditions is met:

  1. The given context is cancelled.
  2. Client.Stop is called.

Generally (2) is preferred because by using Stop you give the client a chance to gracefully try to finish up with any jobs it's currently working. Cancelling the context will cause a "hard stop" that'll throw out existing work.

In your code above, you probably want to have a stopping signal that tries to stop gracefully before going full scorched earth and cancelling everything. e.g.

stopping := make(chan struct{})

// do start up and run

<-stopping
riverClient.Stop(ctx)

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@brandur
Comment options

Answer selected by vsoch
@vsoch
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #469 on July 25, 2024 01:53.