dispatch(new App\Jobs\SendEmails);
public function dispatchNextJobInChain()
{
if (! empty($this->chained)) {
dispatch(tap(unserialize(array_shift($this->chained)), function ($next) {
$next->chained = $this->chained;
$next->onConnection($next->connection ?: $this->chainConnection);
$next->onQueue($next->queue ?: $this->chainQueue);
$next->chainConnection = $this->chainConnection;
$next->chainQueue = $this->chainQueue;
$next->chainCatchCallbacks = $this->chainCatchCallbacks;
}));
}
}
{
if (! empty($this->chained)) {
dispatch(tap(unserialize(array_shift($this->chained)), function ($next) {
$next->chained = $this->chained;
$next->onConnection($next->connection ?: $this->chainConnection);
$next->onQueue($next->queue ?: $this->chainQueue);
$next->chainConnection = $this->chainConnection;
$next->chainQueue = $this->chainQueue;
$next->chainCatchCallbacks = $this->chainCatchCallbacks;
}));
}
}
public function resolve()
{
return function (...$arguments) {
dispatch(new CallQueuedListener(InvokeQueuedClosure::class, 'handle', [
'closure' => new SerializableClosure($this->closure),
'arguments' => $arguments,
'catch' => collect($this->catchCallbacks)->map(function ($callback) {
return new SerializableClosure($callback);
})->all(),
]))->onConnection($this->connection)->onQueue($this->queue)->delay($this->delay);
};
}
}
{
return function (...$arguments) {
dispatch(new CallQueuedListener(InvokeQueuedClosure::class, 'handle', [
'closure' => new SerializableClosure($this->closure),
'arguments' => $arguments,
'catch' => collect($this->catchCallbacks)->map(function ($callback) {
return new SerializableClosure($callback);
})->all(),
]))->onConnection($this->connection)->onQueue($this->queue)->delay($this->delay);
};
}
}
public function testJobsCanBeChainedOnSuccessUsingHelper()
{
dispatch(new JobChainingTestFirstJob)->chain([
new JobChainingTestSecondJob,
]);
{
dispatch(new JobChainingTestFirstJob)->chain([
new JobChainingTestSecondJob,
]);
public function testLockIsReleasedForSuccessfulJobs()
{
UniqueTestJob::$handled = false;
dispatch($job = new UniqueTestJob);
$this->assertTrue($job::$handled);
$this->assertTrue($this->app->get(Cache::class)->lock($this->getLockKey($job), 10)->get());
{
UniqueTestJob::$handled = false;
dispatch($job = new UniqueTestJob);
$this->assertTrue($job::$handled);
$this->assertTrue($this->app->get(Cache::class)->lock($this->getLockKey($job), 10)->get());
$this->expectException(Exception::class);
try {
dispatch($job = new UniqueTestFailJob);
} finally {
$this->assertTrue($job::$handled);
$this->assertTrue($this->app->get(Cache::class)->lock($this->getLockKey($job), 10)->get());
try {
dispatch($job = new UniqueTestFailJob);
} finally {
$this->assertTrue($job::$handled);
$this->assertTrue($this->app->get(Cache::class)->lock($this->getLockKey($job), 10)->get());
{
UniqueTestRetryJob::$handled = false;
dispatch($job = new UniqueTestRetryJob);
$this->assertFalse($this->app->get(Cache::class)->lock($this->getLockKey($job), 10)->get());
UniqueTestRetryJob::$handled = false;
dispatch($job = new UniqueTestRetryJob);
$this->assertFalse($this->app->get(Cache::class)->lock($this->getLockKey($job), 10)->get());
public function testLockIsNotReleasedForJobReleases()
{
UniqueTestReleasedJob::$handled = false;
dispatch($job = new UniqueTestReleasedJob);
$this->assertFalse($this->app->get(Cache::class)->lock($this->getLockKey($job), 10)->get());
{
UniqueTestReleasedJob::$handled = false;
dispatch($job = new UniqueTestReleasedJob);
$this->assertFalse($this->app->get(Cache::class)->lock($this->getLockKey($job), 10)->get());
{
UniqueUntilStartTestJob::$handled = false;
dispatch($job = new UniqueUntilStartTestJob);
$this->assertFalse($this->app->get(Cache::class)->lock($this->getLockKey($job), 10)->get());
UniqueUntilStartTestJob::$handled = false;
dispatch($job = new UniqueUntilStartTestJob);
$this->assertFalse($this->app->get(Cache::class)->lock($this->getLockKey($job), 10)->get());
$job = new TestJob1;
dispatch($job);
dispatch(new TestJob2);
dispatch($job)->onQueue('Q2');
dispatch($job);
dispatch(new TestJob2);
dispatch($job)->onQueue('Q2');
$job = new TestJob1;
dispatch($job);
dispatch(new TestJob2);
dispatch($job)->onQueue('Q2');
$this->assertEquals(2, Queue::size());
dispatch($job);
dispatch(new TestJob2);
dispatch($job)->onQueue('Q2');
$this->assertEquals(2, Queue::size());
dispatch($job);
dispatch(new TestJob2);
dispatch($job)->onQueue('Q2');
$this->assertEquals(2, Queue::size());
$this->assertEquals(1, Queue::size('Q2'));
dispatch(new TestJob2);
dispatch($job)->onQueue('Q2');
$this->assertEquals(2, Queue::size());
$this->assertEquals(1, Queue::size('Q2'));