According to the following tutorial (https://laravel.com/docs/5.5/scheduling) I came up with the following script to schedule Jobs within my Lumen application:
namespace App\Console;
use App\Jobs\ClearAccessLog;
use Illuminate\Console\Scheduling\Schedule;
use Laravel\Lumen\Console\Kernel as ConsoleKernel;
use App\Jobs\Special\DeleteCache;
use App\Jobs\Special\FetchRemoteArticles;
use App\Jobs\Special\FetchUpdateCategories;
use App\Jobs\Special\UpdateArticles;
use Illuminate\Support\Facades\Queue;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->call(function() {
Queue::bulk([
new FetchUpdateCategories,
new FetchRemoteArticles,
new UpdateArticles,
new DeleteCache
],null,'specialqueue');
})->daily();
// listen to
$schedule->job(new ClearAccessLog())->weekly();
// listen to the helpdocs queue
$schedule->command('php artisan queue:work --timeout=0 --memory=4096 --queue=specialqueue')->everyFiveMinutes();
// listen to default jobs
$schedule->command('php artisan queue:work --timeout=0 --memory=4096')->daily();
}
}
According to the docs with my server I only have to register one single cronjob like this:
crontab -e
Then add:
* * * * * php /path-to-my-project/artisan schedule:run >> /dev/null 2>&1
Anyway I noticed that if I execute
php artisan queue:work --timeout=0 --memory=4096 --queue=specialqueue
via SSH this keeps listening until the command is stopped, therefore I am not sure if the Scheduler will start a new background task every five minutes while the others are still running?
How may I start this command only once? In general do you see some obvious mistake (I am new to this topic)?
You are not correct to start queue workers on schedule. Queue workers are daemon that listens if any job to work, if not, then it will sleep until next jobs are available. What you are trying to do is to create infinite queue workers that do not make sense.
You should check the manual Laravel Queues. If you are allowed to install Supervisor, let the supervisor controls your queue worker. Supervisor helps you to monitor queue workers and in any case it fails with some error, it will try to restart.
Or otherwise, you should start the queue worker in background through ssh, and detach the process from the current user. But the queue worker will not restart automatically in case of any failure.