Reputation: 1821
I'm trying to see Laravel Queue working, but got some problems.
So I've added a testJob
protected function schedule(Schedule $schedule)
{
$schedule->job(new TestJob)->everyMinute();
}
The job class does nothing, it's just a test
class TestJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct()
{
//
}
public function handle()
{
//
}
}
As docs says, added the cron to the server
* * * * * cd /home/ec2-user/myproject-prod && php artisan schedule:run >> /dev/null 2>&1
For the last, added supervisor worker
[program:myproject-queue]
process_name=%(program_name)s_%(process_num)02d
command=php /home/ec2-user/myproject-prod/artisan queue:work --sleep=3 --tries=3
autostart=true
autorestart=true
user=ec2-user
numprocs=1
redirect_stderr=true
stdout_logfile=/home/ec2-user/supervisor-myproject-prod.log
So, as the loge below shows, at the same second you can see the same job running multiple times.
Sometimes same job runs once (correctly), a lot of times it runs twice and a few times it works 4 times.
[2019-11-14 08:25:02][5537] Processing: App\Jobs\TestJob
[2019-11-14 08:25:02][5537] Processed: App\Jobs\TestJob
[2019-11-14 08:25:05][5538] Processing: App\Jobs\TestJob
[2019-11-14 08:25:05][5538] Processed: App\Jobs\TestJob
[2019-11-14 08:26:03][5539] Processing: App\Jobs\TestJob
[2019-11-14 08:26:03][5539] Processed: App\Jobs\TestJob
[2019-11-14 08:26:06][5540] Processing: App\Jobs\TestJob
[2019-11-14 08:26:06][5540] Processed: App\Jobs\TestJob
[2019-11-14 08:27:03][5541] Processing: App\Jobs\TestJob
[2019-11-14 08:27:03][5541] Processed: App\Jobs\TestJob
[2019-11-14 08:27:06][5542] Processing: App\Jobs\TestJob
[2019-11-14 08:27:06][5542] Processed: App\Jobs\TestJob
Is was before running 8 processes in supervisor, so I changed to 1 and got the same problem.
Stopping the worker I can see in MySQL jobs queue it looks like correct, adding one job per minute.
So it looks like a conflict in worker.
Is that correct? Am I doing something wrong?
Is Laravel task scheduler ready for production with thousands of jobs?
Upvotes: 5
Views: 4944