Laravel - Jobs


How can we add a new cron job?

Add an Artisan command as mentioned elsewhere. Then, modify the Kernel.php:

protected function schedule(Schedule $schedule) {

Add to your crontab:

* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1

In addition to scheduling Closure calls, you may also schedule Artisan commands and operating system commands. For example, you may use the command method to schedule an Artisan command using either the command's name or class:

$schedule->command('emails:send --force')->daily();
$schedule->command(EmailsCommand::class, ['--force'])->daily();

The exec command may be used to issue a command to the operating system:

$schedule->exec('node /home/forge/script.js')->daily();

See for more scheduling options and examples.

How can we work with Laravel Queue?

php artisan queue:table // Generate the migration file for the queue functionality.
php artisan queue:failed-table // Generate the migration file for the queue functionality for when it fails.
php artisan migrate

Change the configuration settings in config->queue.php (sync: do not use queue or run immediately). Next, create a job:

php artisan make:job LogSomething

Modify the LogSomething.php under app->Jobs to implement the handle method. Then dispatch the job anywhere in the code:

dispatch(new \App\Jobs\LogSomething)

To process the job:

php artisan queue:work
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License