Skip to content

Commit

Permalink
Merge branch '10.x'
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Dec 13, 2023
2 parents 4c1aa68 + 9fe14c8 commit b40fdcd
Show file tree
Hide file tree
Showing 68 changed files with 2,156 additions and 229 deletions.
160 changes: 160 additions & 0 deletions .github/workflows/queues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
name: queues

on:
push:
branches:
- master
- '*.x'
pull_request:

jobs:
sync:
runs-on: ubuntu-22.04

strategy:
fail-fast: true

name: Sync Driver

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr
tools: composer:v2
coverage: none

- name: Install dependencies
uses: nick-fields/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit tests/Integration/Queue
env:
QUEUE_CONNECTION: sync

database:
runs-on: ubuntu-22.04

strategy:
fail-fast: true

name: Database Driver

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr
tools: composer:v2
coverage: none

- name: Install dependencies
uses: nick-fields/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit tests/Integration/Queue
env:
DB_CONNECTION: testing
QUEUE_CONNECTION: database

redis:
runs-on: ubuntu-22.04

services:
redis:
image: redis:7.0
ports:
- 6379:6379
options: --entrypoint redis-server

strategy:
fail-fast: true

name: Redis Driver

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr
tools: composer:v2
coverage: none

- name: Install dependencies
uses: nick-fields/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit tests/Integration/Queue
env:
QUEUE_CONNECTION: redis

beanstalkd:
runs-on: ubuntu-22.04

name: Beanstalkd Driver

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/checkout@v3
- name: Download & Extract beanstalkd
run: curl -L https://github.com/beanstalkd/beanstalkd/archive/refs/tags/v1.13.tar.gz | tar xz
- name: Make beanstalkd
run: make
working-directory: beanstalkd-1.13

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr
tools: composer:v2
coverage: none

- name: Install dependencies
uses: nick-fields/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

- name: Daemonize beanstalkd
run: ./beanstalkd-1.13/beanstalkd &

- name: Execute tests
run: vendor/bin/phpunit tests/Integration/Queue
env:
QUEUE_CONNECTION: beanstalkd
26 changes: 26 additions & 0 deletions src/Illuminate/Bus/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,14 @@ public function recordSuccessfulJob(string $jobId)
{
$counts = $this->decrementPendingJobs($jobId);

if ($this->hasProgressCallbacks()) {
$batch = $this->fresh();

collect($this->options['progress'])->each(function ($handler) use ($batch) {
$this->invokeHandlerCallback($handler, $batch);
});
}

if ($counts->pendingJobs === 0) {
$this->repository->markAsFinished($this->id);
}
Expand Down Expand Up @@ -283,6 +291,16 @@ public function finished()
return ! is_null($this->finishedAt);
}

/**
* Determine if the batch has "progress" callbacks.
*
* @return bool
*/
public function hasProgressCallbacks()
{
return isset($this->options['progress']) && ! empty($this->options['progress']);
}

/**
* Determine if the batch has "success" callbacks.
*
Expand Down Expand Up @@ -328,6 +346,14 @@ public function recordFailedJob(string $jobId, $e)
$this->cancel();
}

if ($this->hasProgressCallbacks() && $this->allowsFailures()) {
$batch = $this->fresh();

collect($this->options['progress'])->each(function ($handler) use ($batch, $e) {
$this->invokeHandlerCallback($handler, $batch, $e);
});
}

if ($counts->failedJobs === 1 && $this->hasCatchCallbacks()) {
$batch = $this->fresh();

Expand Down
36 changes: 35 additions & 1 deletion src/Illuminate/Bus/BusServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Illuminate\Bus;

use Aws\DynamoDb\DynamoDbClient;
use Illuminate\Contracts\Bus\Dispatcher as DispatcherContract;
use Illuminate\Contracts\Bus\QueueingDispatcher as QueueingDispatcherContract;
use Illuminate\Contracts\Queue\Factory as QueueFactoryContract;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\Arr;
use Illuminate\Support\ServiceProvider;

class BusServiceProvider extends ServiceProvider implements DeferrableProvider
Expand Down Expand Up @@ -41,7 +43,13 @@ public function register()
*/
protected function registerBatchServices()
{
$this->app->singleton(BatchRepository::class, DatabaseBatchRepository::class);
$this->app->singleton(BatchRepository::class, function ($app) {
$driver = $app->config->get('queue.batching.driver', 'database');

return $driver === 'dynamodb'
? $app->make(DynamoBatchRepository::class)
: $app->make(DatabaseBatchRepository::class);
});

$this->app->singleton(DatabaseBatchRepository::class, function ($app) {
return new DatabaseBatchRepository(
Expand All @@ -50,6 +58,32 @@ protected function registerBatchServices()
$app->config->get('queue.batching.table', 'job_batches')
);
});

$this->app->singleton(DynamoBatchRepository::class, function ($app) {
$config = $app->config->get('queue.batching');

$dynamoConfig = [
'region' => $config['region'],
'version' => 'latest',
'endpoint' => $config['endpoint'] ?? null,
];

if (! empty($config['key']) && ! empty($config['secret'])) {
$dynamoConfig['credentials'] = Arr::only(
$config,
['key', 'secret', 'token']
);
}

return new DynamoBatchRepository(
$app->make(BatchFactory::class),
new DynamoDbClient($dynamoConfig),
$app->config->get('app.name'),
$app->config->get('queue.batching.table', 'job_batches'),
ttl: $app->config->get('queue.batching.ttl', null),
ttlAttribute: $app->config->get('queue.batching.ttl_attribute', 'ttl'),
);
});
}

/**
Expand Down
Loading

0 comments on commit b40fdcd

Please sign in to comment.