Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions config/queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@
'after_commit' => false,
],

'deferred' => [
'driver' => 'deferred',
],

'failover' => [
'driver' => 'failover',
'connections' => [
'database',
'deferred',
],
],

],

/*
Expand Down
18 changes: 18 additions & 0 deletions src/Illuminate/Queue/Connectors/DeferredConnector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Illuminate\Queue\Connectors;

use Illuminate\Queue\DeferredQueue;

class DeferredConnector implements ConnectorInterface
{
/**
* Establish a queue connection.
*
* @return \Illuminate\Contracts\Queue\Queue
*/
public function connect(array $config)
{
return new DeferredQueue($config['after_commit'] ?? null);
}
}
23 changes: 23 additions & 0 deletions src/Illuminate/Queue/DeferredQueue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Illuminate\Queue;

use Illuminate\Contracts\Queue\Job;

class DeferredQueue extends SyncQueue
{
/**
* Push a new job onto the queue.
*
* @param string $job
* @param mixed $data
* @param string|null $queue
* @return mixed
*
* @throws \Throwable
*/
public function push($job, $data = '', $queue = null)
{
return \Illuminate\Support\defer(fn () => parent::push($job, $data, $queue));
}
}
16 changes: 15 additions & 1 deletion src/Illuminate/Queue/QueueServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Queue\Connectors\BeanstalkdConnector;
use Illuminate\Queue\Connectors\DatabaseConnector;
use Illuminate\Queue\Connectors\DeferredConnector;
use Illuminate\Queue\Connectors\FailoverConnector;
use Illuminate\Queue\Connectors\NullConnector;
use Illuminate\Queue\Connectors\RedisConnector;
Expand Down Expand Up @@ -104,7 +105,7 @@ protected function registerConnection()
*/
public function registerConnectors($manager)
{
foreach (['Null', 'Sync', 'Failover', 'Database', 'Redis', 'Beanstalkd', 'Sqs'] as $connector) {
foreach (['Null', 'Sync', 'Deferred', 'Failover', 'Database', 'Redis', 'Beanstalkd', 'Sqs'] as $connector) {
$this->{"register{$connector}Connector"}($manager);
}
}
Expand Down Expand Up @@ -135,6 +136,19 @@ protected function registerSyncConnector($manager)
});
}

/**
* Register the Deferred queue connector.
*
* @param \Illuminate\Queue\QueueManager $manager
* @return void
*/
protected function registerDeferredConnector($manager)
{
$manager->addConnector('deferred', function () {
return new DeferredConnector;
});
}

/**
* Register the Failover queue connector.
*
Expand Down
Loading