Closed ldmuniz closed 1 year ago
Sadly I can not reproduce this issue.
When executing the following test job which takes 30 seconds to run but specifying --timeout=5
with the artisan queue:work
command, the Queue monitor will correctly mark the job as failed.
Maybe the job is hitting your configured max_execution_time
threshold? In this case it's not possible to mark the previous attempt as failed since the PHP process will be killed immediately. The following attempt will also generate a new job_id
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use romanzipp\QueueMonitor\Traits\IsMonitored;
class TestJob implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use IsMonitored;
use Queueable;
use SerializesModels;
use IsMonitored;
public function handle()
{
sleep(30);
}
public function failed()
{
logger('TIMEOUT OCCURED');
}
}
Same happened to me, I have cases when a job would stop running (I think it is the OS killing the process, still looking into it) and the job would be stuck as running forever
There another possible reason that keep some jobs stuck on running and is when jobs are distributed across multiple Laravel workers on different servers (distributed system).
See https://github.com/romanzipp/Laravel-Queue-Monitor/pull/68 for more details.
I have the same issue with this. Instead of update the existing record, this package creates new row.
How to reproduce:
You'll see a new record in database. Take a look at my example below
I think the given solution by @ldmuniz should work
I've looked into this issue and filed PR #83 which marks previous jobs with the same job id and status "running" as failed.
Could you try out this fix?
@juanparati has submitted a similar PR #68 but i lost track of it since I could not reproduce it on my system.
I'd like to avoid reusing the same monitor instance and overriding the attributes or deleting the previous instance since it I'm currently working on a new database structure which takes stale jobs into consideration
I've tested PR #83, and the problem still occurs.
I suggest you mark the job as finished and set failed as true
since we verify the job status is finished from the isFinished()
method.
Sometimes, when the job hit the timeout, another attempt is created and the original Job stucks on "Running". I suggest a little change in jobStarted function at romanzipp\QueueMonitor\Services\QueueMonitor.php
Original:
Suggestion: