Laravel Job and Queue

To place job on the queue using tinker:

use Illuminate\Contracts\Bus\Dispatcher;
//for command
//for job
app(Dispatcher::class)->dispatch(new App\Jobs\TestJob);
$pending = dispatch(new App\Jobs\TestJob) //must set to a var or it won't dispatch
Queue::pushON('queueName', new App\Jobs\TestJob())

To run worker:

php artisan queue:work

To run worker just once:

php artisan queue:work --once

To restart worker after a code change:

php artisan queue:restart

To get a job to place in the failed queue, first, create a failed_jobs table:

php artisan queue:failed-table

php artisan migrate

After that, in the code, throw exception when you want the job to fail:

throw new \Exception("something terrible has happened");

The job will be placed in the failed queue after the worker has tried as many time as you specified. For example:

php artisan queue:work --tries=1

will invoke a worker that tries to execute the job once. If it failed, it will be placed on the fail queue to be tried later again.

To retry all the failed jobs

php artisan queue:retry all