Skip to content

Commit b40fdcd

Browse files
committed
Merge branch '10.x'
Signed-off-by: Mior Muhammad Zaki <[email protected]>
2 parents 4c1aa68 + 9fe14c8 commit b40fdcd

File tree

68 files changed

+2156
-229
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2156
-229
lines changed

.github/workflows/queues.yml

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
name: queues
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- '*.x'
8+
pull_request:
9+
10+
jobs:
11+
sync:
12+
runs-on: ubuntu-22.04
13+
14+
strategy:
15+
fail-fast: true
16+
17+
name: Sync Driver
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Setup PHP
26+
uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: 8.1
29+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr
30+
tools: composer:v2
31+
coverage: none
32+
33+
- name: Install dependencies
34+
uses: nick-fields/retry@v2
35+
with:
36+
timeout_minutes: 5
37+
max_attempts: 5
38+
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress
39+
40+
- name: Execute tests
41+
run: vendor/bin/phpunit tests/Integration/Queue
42+
env:
43+
QUEUE_CONNECTION: sync
44+
45+
database:
46+
runs-on: ubuntu-22.04
47+
48+
strategy:
49+
fail-fast: true
50+
51+
name: Database Driver
52+
53+
steps:
54+
- name: Checkout code
55+
uses: actions/checkout@v4
56+
with:
57+
fetch-depth: 0
58+
59+
- name: Setup PHP
60+
uses: shivammathur/setup-php@v2
61+
with:
62+
php-version: 8.1
63+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr
64+
tools: composer:v2
65+
coverage: none
66+
67+
- name: Install dependencies
68+
uses: nick-fields/retry@v2
69+
with:
70+
timeout_minutes: 5
71+
max_attempts: 5
72+
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress
73+
74+
- name: Execute tests
75+
run: vendor/bin/phpunit tests/Integration/Queue
76+
env:
77+
DB_CONNECTION: testing
78+
QUEUE_CONNECTION: database
79+
80+
redis:
81+
runs-on: ubuntu-22.04
82+
83+
services:
84+
redis:
85+
image: redis:7.0
86+
ports:
87+
- 6379:6379
88+
options: --entrypoint redis-server
89+
90+
strategy:
91+
fail-fast: true
92+
93+
name: Redis Driver
94+
95+
steps:
96+
- name: Checkout code
97+
uses: actions/checkout@v4
98+
with:
99+
fetch-depth: 0
100+
101+
- name: Setup PHP
102+
uses: shivammathur/setup-php@v2
103+
with:
104+
php-version: 8.1
105+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr
106+
tools: composer:v2
107+
coverage: none
108+
109+
- name: Install dependencies
110+
uses: nick-fields/retry@v2
111+
with:
112+
timeout_minutes: 5
113+
max_attempts: 5
114+
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress
115+
116+
- name: Execute tests
117+
run: vendor/bin/phpunit tests/Integration/Queue
118+
env:
119+
QUEUE_CONNECTION: redis
120+
121+
beanstalkd:
122+
runs-on: ubuntu-22.04
123+
124+
name: Beanstalkd Driver
125+
126+
steps:
127+
- name: Checkout code
128+
uses: actions/checkout@v4
129+
with:
130+
fetch-depth: 0
131+
132+
- uses: actions/checkout@v3
133+
- name: Download & Extract beanstalkd
134+
run: curl -L https://github.com/beanstalkd/beanstalkd/archive/refs/tags/v1.13.tar.gz | tar xz
135+
- name: Make beanstalkd
136+
run: make
137+
working-directory: beanstalkd-1.13
138+
139+
- name: Setup PHP
140+
uses: shivammathur/setup-php@v2
141+
with:
142+
php-version: 8.1
143+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr
144+
tools: composer:v2
145+
coverage: none
146+
147+
- name: Install dependencies
148+
uses: nick-fields/retry@v2
149+
with:
150+
timeout_minutes: 5
151+
max_attempts: 5
152+
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress
153+
154+
- name: Daemonize beanstalkd
155+
run: ./beanstalkd-1.13/beanstalkd &
156+
157+
- name: Execute tests
158+
run: vendor/bin/phpunit tests/Integration/Queue
159+
env:
160+
QUEUE_CONNECTION: beanstalkd

src/Illuminate/Bus/Batch.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,14 @@ public function recordSuccessfulJob(string $jobId)
241241
{
242242
$counts = $this->decrementPendingJobs($jobId);
243243

244+
if ($this->hasProgressCallbacks()) {
245+
$batch = $this->fresh();
246+
247+
collect($this->options['progress'])->each(function ($handler) use ($batch) {
248+
$this->invokeHandlerCallback($handler, $batch);
249+
});
250+
}
251+
244252
if ($counts->pendingJobs === 0) {
245253
$this->repository->markAsFinished($this->id);
246254
}
@@ -283,6 +291,16 @@ public function finished()
283291
return ! is_null($this->finishedAt);
284292
}
285293

294+
/**
295+
* Determine if the batch has "progress" callbacks.
296+
*
297+
* @return bool
298+
*/
299+
public function hasProgressCallbacks()
300+
{
301+
return isset($this->options['progress']) && ! empty($this->options['progress']);
302+
}
303+
286304
/**
287305
* Determine if the batch has "success" callbacks.
288306
*
@@ -328,6 +346,14 @@ public function recordFailedJob(string $jobId, $e)
328346
$this->cancel();
329347
}
330348

349+
if ($this->hasProgressCallbacks() && $this->allowsFailures()) {
350+
$batch = $this->fresh();
351+
352+
collect($this->options['progress'])->each(function ($handler) use ($batch, $e) {
353+
$this->invokeHandlerCallback($handler, $batch, $e);
354+
});
355+
}
356+
331357
if ($counts->failedJobs === 1 && $this->hasCatchCallbacks()) {
332358
$batch = $this->fresh();
333359

src/Illuminate/Bus/BusServiceProvider.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace Illuminate\Bus;
44

5+
use Aws\DynamoDb\DynamoDbClient;
56
use Illuminate\Contracts\Bus\Dispatcher as DispatcherContract;
67
use Illuminate\Contracts\Bus\QueueingDispatcher as QueueingDispatcherContract;
78
use Illuminate\Contracts\Queue\Factory as QueueFactoryContract;
89
use Illuminate\Contracts\Support\DeferrableProvider;
10+
use Illuminate\Support\Arr;
911
use Illuminate\Support\ServiceProvider;
1012

1113
class BusServiceProvider extends ServiceProvider implements DeferrableProvider
@@ -41,7 +43,13 @@ public function register()
4143
*/
4244
protected function registerBatchServices()
4345
{
44-
$this->app->singleton(BatchRepository::class, DatabaseBatchRepository::class);
46+
$this->app->singleton(BatchRepository::class, function ($app) {
47+
$driver = $app->config->get('queue.batching.driver', 'database');
48+
49+
return $driver === 'dynamodb'
50+
? $app->make(DynamoBatchRepository::class)
51+
: $app->make(DatabaseBatchRepository::class);
52+
});
4553

4654
$this->app->singleton(DatabaseBatchRepository::class, function ($app) {
4755
return new DatabaseBatchRepository(
@@ -50,6 +58,32 @@ protected function registerBatchServices()
5058
$app->config->get('queue.batching.table', 'job_batches')
5159
);
5260
});
61+
62+
$this->app->singleton(DynamoBatchRepository::class, function ($app) {
63+
$config = $app->config->get('queue.batching');
64+
65+
$dynamoConfig = [
66+
'region' => $config['region'],
67+
'version' => 'latest',
68+
'endpoint' => $config['endpoint'] ?? null,
69+
];
70+
71+
if (! empty($config['key']) && ! empty($config['secret'])) {
72+
$dynamoConfig['credentials'] = Arr::only(
73+
$config,
74+
['key', 'secret', 'token']
75+
);
76+
}
77+
78+
return new DynamoBatchRepository(
79+
$app->make(BatchFactory::class),
80+
new DynamoDbClient($dynamoConfig),
81+
$app->config->get('app.name'),
82+
$app->config->get('queue.batching.table', 'job_batches'),
83+
ttl: $app->config->get('queue.batching.ttl', null),
84+
ttlAttribute: $app->config->get('queue.batching.ttl_attribute', 'ttl'),
85+
);
86+
});
5387
}
5488

5589
/**

0 commit comments

Comments
 (0)