In Laravel 7 I use supervisor in my production server(Ubuntu) to get some jobs running automatically.
in local env everything work well. but in my production server every job queuing twice.
This my command
public function handle()
{
dispatch(new JobsCreateStatement());
}
If I do not queue the job and execute immediately there is no issue (only one job executed) like below
public function handle()
{
dispatch_now(new JobsCreateStatement());
}
If I dispatch manually a job inside my controller also not an issue (only one job executed)
public function test()
{
dispatch(new JobsCreateStatement());
}
This is my job handle method
public function handle()
{
Log::info("inside create statement job............");
//Mail::to('[email protected]')->queue(new MailStatement());
}
This is Kernel.php
protected $commands = [
//.... other commands
'App\Console\Commands\CreateStatement',
];
protected function schedule(Schedule $schedule)
{
//...... other commands
$schedule->command('create:statement')->hourly();
}
This is crontab entry in ubuntu
# m h dom mon dow command
* * * * * /usr/bin/php /var/www/html/moving/artisan schedule:run >> /dev/null 2>&1
This my supervisor configuration
[program:queueworker]
process_name=%(program_name)s_%(process_num)02d
command=/usr/bin/php /var/www/html/moving/artisan queue:listen
numprocs=1
autostart=true
autorestart=true
user=www-data
stderr_logfile=/var/www/html/moving/public/worker_err.log
stdout_logfile=/var/www/html/moving/public/worker.log
This is the output
tingsapp@tingsapp-dev:/var/www/html/moving$ tail -f storage/logs/laravel.log
[2024-02-05 14:40:04] local.INFO: inside crate statement job............
[2024-02-05 14:40:05] local.INFO: inside crate statement job............
In the output you see that the first one is executed at 2024-02-05 14:40:04 and second one executed at 2024-02-05 14:40:04 same time, but some time the second and first differs 1 second only.
Any help please?