Skip to content

Possible to use "ratelimited" middleware on activities ? #228

Answered by rmcdaniel
franck-grenier asked this question in Q&A
Discussion options

You must be logged in to vote

Here is how you would do that. Here is some example middleware.

<?php

declare(strict_types=1);

namespace App\Workflows\Simple;

class SimpleMiddleware
{
    public function handle($job, $next): void
    {
        $next($job);
    }
}

And here is our activity.

<?php

declare(strict_types=1);

namespace App\Workflows\Simple;

use Workflow\Activity;

class SimpleActivity extends Activity
{
    public function middleware()
    {
        $middleware = parent::middleware();
        array_splice($middleware, 1, 0, [SimpleMiddleware::class]);
        return $middleware;
    }

    public function execute()
    {
        return 'activity';
    }
}

The array_splice() will put the middleware in …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by franck-grenier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy