Skip to content

Instantly share code, notes, and snippets.

@jbrooksuk jbrooksuk/locker.php
Created Jun 20, 2016

Embed
What would you like to do?
AltThree/Locker Usage
<?php
namespace App\Bus\Middleware;
use AltThree\Locker\Locker;
use Closure;
use Illuminate\Contracts\Queue\ShouldQueue;
class LockingMiddleware
{
use NameTrait;
/**
* The locker instance.
*
* @var \AltThree\Locker\Locker
*/
protected $locker;
/**
* Create a new locking middleware instance.
*
* @param \AltThree\Locker\Locker $locker
*
* @return void
*/
public function __construct(Locker $locker)
{
$this->locker = $locker;
}
/**
* Aquire a lock for the command before execution.
*
* @param object $command
* @param \Closure $next
*
* @return void
*/
public function handle($command, Closure $next)
{
$function = function () use ($command, $next) {
return $next($command);
};
$name = $this->name($command);
$timeout = $command instanceof ShouldQueue ? 200000 : 60000;
return $this->locker->execute($function, $name, $timeout);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.