Client from worker context

The River client is made available to workers on the context, making it easy to enqueue additional jobs from within a job.

Basic usage

The River client working a job is stored in a value on the context provided to workers. The client can be retrieved from the context (or any contexts derived from it) using the ClientFromContext helper:

client := river.ClientFromContext(ctx)

If ClientFromContext is called on a context which isn't derived from the work context, it will panic. This situation indicates a programming error so most users will find the panic more convenient, although a non-panicking version is also available:

client, err := river.ClientFromContextSafely(ctx)
Cancelling jobs