Skip to content

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

Merged
taylorotwell merged 2 commits into
laravel:9.xfrom
timacdonald:share-without-overlapping-key
Sep 21, 2022
Merged

[9.x] Share WithoutOverlapping key across jobs#44227
taylorotwell merged 2 commits into
laravel:9.xfrom
timacdonald:share-without-overlapping-key

Conversation

@timacdonald

@timacdonald timacdonald commented Sep 21, 2022

Copy link
Copy Markdown
Member

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
Copy Markdown

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

@timacdonald

Copy link
Copy Markdown
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