Skip to content

Commit 31abad6

Browse files
authored
Deferred queue (#57428)
* add deferred queue * adjust config * update config
1 parent 95c33ca commit 31abad6

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

config/queue.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@
7272
'after_commit' => false,
7373
],
7474

75+
'deferred' => [
76+
'driver' => 'deferred',
77+
],
78+
79+
'failover' => [
80+
'driver' => 'failover',
81+
'connections' => [
82+
'database',
83+
'deferred',
84+
],
85+
],
86+
7587
],
7688

7789
/*
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Illuminate\Queue\Connectors;
4+
5+
use Illuminate\Queue\DeferredQueue;
6+
7+
class DeferredConnector implements ConnectorInterface
8+
{
9+
/**
10+
* Establish a queue connection.
11+
*
12+
* @return \Illuminate\Contracts\Queue\Queue
13+
*/
14+
public function connect(array $config)
15+
{
16+
return new DeferredQueue($config['after_commit'] ?? null);
17+
}
18+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Illuminate\Queue;
4+
5+
use Illuminate\Contracts\Queue\Job;
6+
7+
class DeferredQueue extends SyncQueue
8+
{
9+
/**
10+
* Push a new job onto the queue.
11+
*
12+
* @param string $job
13+
* @param mixed $data
14+
* @param string|null $queue
15+
* @return mixed
16+
*
17+
* @throws \Throwable
18+
*/
19+
public function push($job, $data = '', $queue = null)
20+
{
21+
return \Illuminate\Support\defer(fn () => parent::push($job, $data, $queue));
22+
}
23+
}

src/Illuminate/Queue/QueueServiceProvider.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Contracts\Support\DeferrableProvider;
99
use Illuminate\Queue\Connectors\BeanstalkdConnector;
1010
use Illuminate\Queue\Connectors\DatabaseConnector;
11+
use Illuminate\Queue\Connectors\DeferredConnector;
1112
use Illuminate\Queue\Connectors\FailoverConnector;
1213
use Illuminate\Queue\Connectors\NullConnector;
1314
use Illuminate\Queue\Connectors\RedisConnector;
@@ -104,7 +105,7 @@ protected function registerConnection()
104105
*/
105106
public function registerConnectors($manager)
106107
{
107-
foreach (['Null', 'Sync', 'Failover', 'Database', 'Redis', 'Beanstalkd', 'Sqs'] as $connector) {
108+
foreach (['Null', 'Sync', 'Deferred', 'Failover', 'Database', 'Redis', 'Beanstalkd', 'Sqs'] as $connector) {
108109
$this->{"register{$connector}Connector"}($manager);
109110
}
110111
}
@@ -135,6 +136,19 @@ protected function registerSyncConnector($manager)
135136
});
136137
}
137138

139+
/**
140+
* Register the Deferred queue connector.
141+
*
142+
* @param \Illuminate\Queue\QueueManager $manager
143+
* @return void
144+
*/
145+
protected function registerDeferredConnector($manager)
146+
{
147+
$manager->addConnector('deferred', function () {
148+
return new DeferredConnector;
149+
});
150+
}
151+
138152
/**
139153
* Register the Failover queue connector.
140154
*

0 commit comments

Comments
 (0)