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

[9.x] Share WithoutOverlapping key across jobs #44227

Merged
merged 2 commits into from
Sep 21, 2022

Conversation

timacdonald
Copy link
Member

@timacdonald timacdonald commented Sep 21, 2022

This PR allows WithoutOverlapping to apply across different job classes. Currently this feature only allows without overlapping to be applied to instances of a single class.

use Illuminate\Queue\Middleware\WithoutOverlapping;

class ProviderIsDown
{
    // ...


    public function middleware()
    {
        return [
            (new WithoutOverlapping("provider-status:{$this->provider}"))->shareKey(),
        ];
    }
}

class ProviderIsUp
{
    // ...


    public function middleware()
    {
        return [
            (new WithoutOverlapping("provider-status:{$this->provider}"))->shareKey(),
        ];
    }
}

These two jobs will now not overlap even though they are different classes. They both utilise the same lock key (assuming the provider is the same) `"provider-status:{providerName}".

Thanks @andrewbroberg for raising and chatting to me about this.

Documentation PR: laravel/docs#8240

@taylorotwell taylorotwell merged commit 6170f0b into laravel:9.x Sep 21, 2022
@timacdonald timacdonald deleted the share-without-overlapping-key branch September 26, 2022 23:49
@rihardsgrislis
Copy link

Hah, I ran into the same constraint earlier last week and wanted to contribute but you beat me to it. 😄
Thanks!

@timacdonald
Copy link
Member Author

No troubles! Glad to hear it will be useful :)

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.

3 participants