contribsys / faktory

Language-agnostic persistent background job server
https://contribsys.com/faktory/
Other
5.71k stars 228 forks source link

Retries can't distinguish between default 0 and explicit 0 #385

Closed mperham closed 2 years ago

mperham commented 2 years ago

When creating an empty job via job := &client.Job{} the Retry value defaults to 0. This makes it impossible to tell if the user meant to set retries to 0 or if they wish to use the default retry policy of 25. client.NewJob already handles this but there are cases were we can't use a helper method to create the initial job structure (e.g. when deserializing from JSON).

Instead update the type from int to *int so the default value is nil. Nil will result in the default retry policy. To set retries explicitly, you'd do something like this:

job := client.NewJob()
job.Retry = &client.RetryPolicyDefault // 25
job.Retry = &client.RetryPolicyEphemeral // 0
job.Retry = &client.RetryPolicyDirectToMorgue // -1

This is backwards incompatible; I hope that most people are using client.NewJob to create their jobs in FWG so this change will be transparent to them.

mperham commented 2 years ago

This change was necessary to implement the PUSHB command in #386.