Fork me on GitHub
#proletarian
<
2024-03-08
>
Santeri Korri07:03:32

New Proletarian user here as well. Thanks for the great library! I have some recurring jobs I want to run in a cluster so that exactly one node executes the job at any scheduled time. My current working hypothesis is to use a) Chime for scheduling, b) Proletarian for at-least-once + retries, c) custom table with timestamp (from Chime) + job-type + locking when enqueuing to get at-most-once behaviour. Does this sound sane? Have I missed some Proletarian functionality/pattern that supports clustered at-most-once out of the box? In case there's no existing way to do this, would it be wildly out of scope for Proletarian to support at-most-once behaviour by accepting an additional key when enqueuing a job (I could try my hand at creating a PR).

msolli12:03:21

Hi @U06NME2EQ4U, thanks for using Proletarian! Like @U02HPS0397S says, Proletarian is "at-most-once" in the happy path - when no exceptions occur during processing of the job. If there is a failure it will get processed again, however. This is to provide the at least one guarantee that we absolutely want.

msolli12:03:36

Out the box Proletarian can do "[...] exactly one node executes the job at any scheduled time". This is the bread and butter of Proletarian. But we have to consider failure and retries, too. A job might have done all there is to do (call a third party API, for example), yet fail just before Proletarian can commit its finished state to the database - then it will be retried (if configured to do so), and it's on you, the developer, to ensure that the effect of the job, when run again, is the same as if it was only run once. This is idempotency. (You might tolerate, in your business domain, that the effect happens twice or more. In that case you don't have to implement your own idempotency checks.)

Santeri Korri08:03:22

Yes, idempotency checks are the key thing here, as every node in the cluster will try to schedule the same job and it should only be executed once per any scheduled time. I guess the specific exact requirements for idempotency vary so much between use cases that it probably makes sense to roll your own implementation. Thanks for taking the time to address this!

👍 1