Skip to content

Commit

Permalink
Initial commit. Not ready yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyppe committed Jan 20, 2024
0 parents commit 0f2c219
Show file tree
Hide file tree
Showing 4 changed files with 393 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
vendor
composer.lock
.bashrc
.idea
30 changes: 30 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "cyppe/laravel-batch-jobs-redis-driver",
"description": "Redis driver for handling batch jobs in Laravel instead of default mysql table job_batches",
"autoload": {
"psr-4": {
"Cyppe\\LaravelBatchJobsRedisDriver\\": "src/"
}
},
"authors": [
{
"name": "cyppe",
"email": "[email protected]"
}
],
"require": {
"php": "^8.0",
"illuminate/support": "^10.0",
"illuminate/bus": "^10.0",
"illuminate/database": "^10.0",
"illuminate/redis": "^10.0",
"ext-redis": "*"
},
"extra": {
"laravel": {
"providers": [
"Cyppe\\LaravelBatchJobsRedisDriver\\CustomBusServiceProvider"
]
}
}
}
28 changes: 28 additions & 0 deletions src/CustomBusServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Cyppe\LaravelBatchJobsRedisDriver;

use Illuminate\Bus\BatchRepository;
use Illuminate\Bus\BusServiceProvider;
use Cyppe\LaravelBatchJobsRedisDriver\Repositories\RedisBatchRepository;

class CustomBusServiceProvider extends BusServiceProvider
{
protected function registerBatchServices()
{
$this->app->singleton(
BatchRepository::class, function ( $app ) {
$driver = config( 'queue.batching.database' );
if ( $driver === 'redis' ) {
$factory = $app->make( \Illuminate\Bus\BatchFactory::class );
return new RedisBatchRepository(
$factory
);
}

// Fallback to parent method if not using Redis
return parent::registerBatchServices();
}
);
}
}
Loading

0 comments on commit 0f2c219

Please sign in to comment.