5

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?

2
  • Does the available_at field get filled in correctly when the job executes? Commented Nov 14, 2019 at 10:56
  • @Jerodev yes, each job has one minute available_at field Commented Nov 14, 2019 at 10:59

1 Answer 1

2

Try..

php artisan queue:work --tries=1
Sign up to request clarification or add additional context in comments.

2 Comments

There doesn't seem to be any failed jobs, so this shouldn't change the behavior.
running for 4 minutes and its correct so far. I will keep it running and check

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.