riverqueue / river

Fast and reliable background jobs in Go
https://riverqueue.com
Mozilla Public License 2.0
3.43k stars 90 forks source link

Insert jobs from workers #406

Closed javirln closed 3 months ago

javirln commented 3 months ago

Hello folks!

Thank you for the fantastic library. I am excited about the upcoming features!

I have a question regarding job scheduling within a worker. Specifically, I am looking to insert jobs to be executed from within a worker. For instance, imagine a scenario where a primary job performs substantial processing but reaches a point where it needs to initiate another job, either scheduled or triggered immediately.

I reviewed the API but couldn't find a solution for this requirement. Is it currently possible to achieve this functionality? If not, could this be considered for a future feature? I understand it may be complex due to the river client requiring worker setup for initialization.

brandur commented 3 months ago

Hi @javirln, check out docs on getting a client from worker context:

https://riverqueue.com/docs/context-client

Another way to do this is to take your initialized client and make it available to all your workers through something like a shared, embedded struct.

javirln commented 3 months ago

Thank you so much @brandur!