I have a queued job, which must runs a code for importing data, like images. I have followed the docs about Laravel 5.8 for creating a job. First crete tables:
php artisan queue:table
php artisan migrate
Then create a job:
php artisan make:job CarsJob
CarsJob:
public function handle() {
$cars = new CarsLibrary();
$CarsLibrary->importAll();
}
Dispatching a job in the controller:
$importCarsJob = (new ImportCarsJob())->onQueue('import_cars');
$this->dispatch($importCarsJob );
OR:
$importCarsJob = new importCarsJob();
$this->dispatch($importCarsJob);
This is my env
file for Redis:
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=redis
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=43216
This is config/queue.php
:
'default' => env('QUEUE_CONNECTION', 'redis'),
'connections' => [
'sync' => [
'driver' => 'redis',
],
... other drivers like beanstalkd
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 90,
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => env('REDIS_QUEUE', 'default'),
],
],
, but when I access the URL for the action with queued job, nothing happen, nothing is imported and there is almost no delay for the response (without queued job, it takes more than a minute ).
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire