Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Add option to release unique job locks before processing #35255

Merged
merged 2 commits into from Nov 18, 2020
Merged

[8.x] Add option to release unique job locks before processing #35255

merged 2 commits into from Nov 18, 2020

Conversation

paras-malhotra
Copy link
Contributor

@paras-malhotra paras-malhotra commented Nov 17, 2020

Based on our discussion at #35042, there may be use cases where it is desirable to release unique job locks before the job starts processing (to avoid race conditions between job completion and unlocking). This PR allows the option to release the unique job lock before processing if the $uniqueUntilStart is set to true like so:

class ExampleJob implements ShouldQueue, ShouldBeUnique
{
    use InteractsWithQueue, Queueable, Dispatchable;

    public $uniqueUntilStart = true;
}

This is backwards-compatible. If the job raises an error, we don't attempt to re-acquire the lock and may be duplicate enqueued. This should be fine as anyone who wants to use this feature would need to make sure that the job is idempotent because a duplicate job dispatch can happen while the job is processing. This is similar to Sidekiq's unique_until start feature.

@paras-malhotra
Copy link
Contributor Author

@taylorotwell I've added a variable to ensure the lock is released only once in the job lifecycle.

@taylorotwell
Copy link
Member

Are we certain that the failed method is called on the same instance so that the variable's value is still in place?

@taylorotwell taylorotwell merged commit 2a6e9d3 into laravel:8.x Nov 18, 2020
@taylorotwell
Copy link
Member

Got rid of property. Added interface:

class SomeJob implements ShouldBeUniqueUntilProcessing
{

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants