Browse Source

Update README for queue supervisor config

dev
Orzu Ionut 2 years ago
parent
commit
aeb7012e6f
  1. 23
      README.md
  2. 79
      app/Console/Commands/DeployWorker.php

23
README.md

@ -74,6 +74,27 @@ cd DEWARP_INSTALLATION_DIRECTORY
pip3 install -r requirements.txt
```
### Queues Supervisor config
Add a new Supervisor config file in the "/etc/supervisor/conf.d" path like in the example below:
Config file path: /etc/supervisor/conf.d/queue-worker-search-and-displace-ingest-production.conf
```bash
[program:queue-worker-search-and-displace-ingest-production]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/searchanddisplace-ingest/artisan queue:listen --queue=sd_ingest,default --tries=2 --timeout=180
autostart=true
autorestart=true
user=www-data
numprocs=3
redirect_stderr=true
stdout_logfile=/var/log/queue/queue-worker-search-and-displace-ingest-production.log
```
The value for the 'command' key should reflect the app path (in the example above the app's path is "/var/www/html/searchanddisplace-ingest").
The 'stdout_logfile' value is the log file. All parent directories must already exist.
### Install app
```bash
# Generate environment file
@ -88,8 +109,6 @@ php artisan key:generate
# Change the value for the QUEUE_CONNECTION to redis, if it is not set already
# Deploy supervisor
php artisan queue:deploy-supervisor
supervisorctl start all
```

79
app/Console/Commands/DeployWorker.php

@ -1,79 +0,0 @@
<?php
namespace App\Console\Commands;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
class DeployWorker extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'queue:deploy-supervisor';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Adds the supervisorctl config file for laravel queues. Must be ran as root!';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$workerName = 'queue-worker-'.str_replace(' ', '-', strtolower(env('APP_NAME'))).'-'.str_replace(' ', '-', strtolower(env('APP_ENV')));
$workerFile = $workerName.'.conf';
try {
Storage::disk('supervisor')->put($workerFile, '[program:'.$workerName.']
process_name=%(program_name)s_%(process_num)02d');
Storage::disk('supervisor')->append($workerFile, 'command=php '.base_path().'/artisan queue:listen --queue=sd_ingest,default --tries=2 --timeout=180');
Storage::disk('supervisor')->append($workerFile, 'autostart=true
autorestart=true
user=www-data
numprocs=3
redirect_stderr=true
stdout_logfile=/var/log/queue/'.$workerName.'.log');
} catch (Exception $e) {
$this->info('supervisor script failed to install. Did you install supervisor and are you running this script as root?');
return;
}
$this->info('supervisor script installed');
try {
exec('sudo supervisorctl reread');
exec('sudo supervisorctl update');
exec('sudo supervisorctl stop '.$workerName.':*');//in case it's already started
exec('sudo supervisorctl start '.$workerName.':*');
} catch (Exception $e) {
$this->info('failed to start queue worker');
return;
}
$this->info('queue worker started');
}
}
Loading…
Cancel
Save