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

[6.0] Job Middleware #29391

Merged
merged 5 commits into from Aug 2, 2019

Conversation

@taylorotwell
Copy link
Member

commented Aug 2, 2019

This adds an easy way to have job specific middleware for queued jobs. Global job middleware were actually already possible by calling Bus::pipeThrough([]) in a service provider during the application boot process.

Middleware may be specified for a job by defining a middleware method on the job which returns an array of middleware objects:

public function middleware()
{
     return [new SomeMiddleware];
}

Middleware look like this:

class SomeMiddleware
{
    public function handle($command, $next)
    {
        // Do something...

        return $next($command);
    }
}

These middleware provide a convenient location to wrap jobs in some logic before they are executed.

You may also specify middleware when dispatching the job. These middleware will be merged with any middleware returned by the middleware method:

SomeJob::dispatch()->through([new SomeMiddleware]);

taylorotwell added some commits Aug 2, 2019

@taylorotwell taylorotwell merged commit 10c8c79 into master Aug 2, 2019

2 of 4 checks passed

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
continuous-integration/travis-ci/push The Travis CI build is in progress
Details
continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/styleci/push The analysis has passed
Details

@taylorotwell taylorotwell deleted the job-middleware branch Aug 2, 2019

@viezel

This comment has been minimized.

Copy link

commented Aug 2, 2019

Yes 👏🏻👏🏻

@fgilio

This comment has been minimized.

Copy link
Contributor

commented Aug 2, 2019

This is great to cleanup multi tenancy related code 😍

@imsidz

This comment has been minimized.

Copy link

commented Aug 3, 2019

👏🏻👏🏻👏🏻👏🏻👏🏻👏🏻👏🏻👏🏻👏🏻👏🏻👏🏻👏🏻👏🏻👏🏻

@GrahamCampbell GrahamCampbell changed the title Job Middleware [6.0] Job Middleware Aug 3, 2019

@ayolana

This comment has been minimized.

Copy link

commented Aug 3, 2019

Great

@autaut03

This comment has been minimized.

Copy link

commented Aug 5, 2019

Could someone explain to me any real-life use case of this feature?

@dipenparmar12

This comment has been minimized.

Copy link

commented Aug 6, 2019

Wow...👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.