Created
September 8, 2019 15:41
-
-
Save milinmestry/81c05fa334937d2a093706d2f2f7fb24 to your computer and use it in GitHub Desktop.
Laravel 5.6 Queues multiple database example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use App\Http\Requests; | |
use Illuminate\Http\Request; | |
use App\Jobs\DemoQueue; | |
/** | |
* Class HomeController | |
* @package App\Http\Controllers | |
*/ | |
class HomeController extends Controller | |
{ | |
private $viewData; | |
/** | |
* Create a new controller instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
$this->middleware('auth'); | |
$this->viewData = [ | |
'slug' => 'dashboard', | |
'childSlug' => '', | |
]; | |
} | |
/** | |
* Show the application dashboard. | |
* | |
* @return Response | |
*/ | |
public function index() | |
{ | |
return view('adminlte::home', [ | |
'activeMenu' => $this->viewData, | |
]); | |
} | |
public function demoJob() { | |
DemoQueue::dispatch()->onQueue('database1')->delay(now()->addMinutes(2)); | |
DemoQueue::dispatch()->onQueue('default')->delay(now()->addMinutes(4)); | |
echo "Done"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cat /etc/supervisor/conf.d/laravel-travel.conf | |
[program:laravel-worker] | |
process_name=%(program_name)s_%(process_num)02d | |
command=php /var/www/html/laravel-admin-lts/artisan queue:work database --queue=database1,default --sleep=3 --tries=3 | |
autostart=true | |
autorestart=true | |
user=www-data | |
numprocs=8 | |
redirect_stderr=true | |
stdout_logfile=/var/www/html/laravel-admin-lts/storage/logs/supervisor-workers.log |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return [ | |
/* | |
|-------------------------------------------------------------------------- | |
| Default Queue Connection Name | |
|-------------------------------------------------------------------------- | |
| | |
| Laravel's queue API supports an assortment of back-ends via a single | |
| API, giving you convenient access to each back-end using the same | |
| syntax for every one. Here you may define a default connection. | |
| | |
*/ | |
'default' => env('QUEUE_CONNECTION', 'sync'), | |
/* | |
|-------------------------------------------------------------------------- | |
| Queue Connections | |
|-------------------------------------------------------------------------- | |
| | |
| Here you may configure the connection information for each server that | |
| is used by your application. A default configuration has been added | |
| for each back-end shipped with Laravel. You are free to add more. | |
| | |
| Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null" | |
| | |
*/ | |
'connections' => [ | |
'sync' => [ | |
'driver' => 'sync', | |
], | |
'database' => [ | |
'driver' => 'database', | |
'table' => 'jobs', | |
'queue' => 'default', | |
'retry_after' => 90, | |
], | |
'database1' => [ | |
'driver' => 'database', | |
'table' => 'jobs', | |
'queue' => 'database1', | |
'retry_after' => 90, | |
], | |
'beanstalkd' => [ | |
'driver' => 'beanstalkd', | |
'host' => 'localhost', | |
'queue' => 'default', | |
'retry_after' => 90, | |
'block_for' => 0, | |
], | |
'sqs' => [ | |
'driver' => 'sqs', | |
'key' => env('AWS_ACCESS_KEY_ID'), | |
'secret' => env('AWS_SECRET_ACCESS_KEY'), | |
'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'), | |
'queue' => env('SQS_QUEUE', 'your-queue-name'), | |
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), | |
], | |
'redis' => [ | |
'driver' => 'redis', | |
'connection' => 'default', | |
'queue' => env('REDIS_QUEUE', 'default'), | |
'retry_after' => 90, | |
'block_for' => null, | |
], | |
], | |
/* | |
|-------------------------------------------------------------------------- | |
| Failed Queue Jobs | |
|-------------------------------------------------------------------------- | |
| | |
| These options configure the behavior of failed queue job logging so you | |
| can control which database and table are used to store the jobs that | |
| have failed. You may change them to any database / table you wish. | |
| | |
*/ | |
'failed' => [ | |
'database' => env('DB_CONNECTION', 'mysql'), | |
'table' => 'failed_jobs', | |
], | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment