Skip to content

Commit

Permalink
[10.x] Enable DynamoDB as a backend for Job Batches (#49169)
Browse files Browse the repository at this point in the history
* Enable DynamoDB as a backend for Job Batches

* Update TTL on updates

* port

* ttl validation

* hmm

* hmm

* hmm

* hmm

* hmm

* hmm

* simpler

* simpler

* move

* recorder

* correct endpoint

* Dynamo pod not accessible from windows

* short ttl

* Fallback to consistent reads

* style ci

* style ci

* style ci

* style ci

* style ci

* Unnecessary style changes

* rollback

* formatting

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
khepin and taylorotwell committed Dec 9, 2023
1 parent 234444e commit d6ecd07
Show file tree
Hide file tree
Showing 4 changed files with 787 additions and 1 deletion.
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 d6ecd07

Please sign in to comment.