Skip to content

Commit 3cbbb3d

Browse files
authored
Add timeout handling. (#437)
2 parents 38f5659 + 9bf4712 commit 3cbbb3d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Queue/Processor.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ class Processor {
7676
*/
7777
protected QueueProcessesTable $QueueProcesses;
7878

79+
/**
80+
* @var \Queue\Model\Entity\QueuedJob|null
81+
*/
82+
protected ?QueuedJob $currentJob = null;
83+
7984
/**
8085
* @param \Queue\Console\Io $io
8186
* @param \Psr\Log\LoggerInterface $logger
@@ -199,6 +204,7 @@ public function run(array $args): int {
199204
* @return void
200205
*/
201206
protected function runJob(QueuedJob $queuedJob, string $pid): void {
207+
$this->currentJob = $queuedJob;
202208
$this->io->out('Running Job of type "' . $queuedJob->job_task . '"');
203209
$this->log('job ' . $queuedJob->job_task . ', id ' . $queuedJob->id, $pid, false);
204210
$taskName = $queuedJob->job_task;
@@ -246,6 +252,7 @@ protected function runJob(QueuedJob $queuedJob, string $pid): void {
246252

247253
$this->QueuedJobs->markJobDone($queuedJob);
248254
$this->io->out('Job Finished.');
255+
$this->currentJob = null;
249256
}
250257

251258
/**
@@ -318,6 +325,12 @@ protected function getTaskConf(): array {
318325
* @return void
319326
*/
320327
protected function exit(int $signal): void {
328+
if ($this->currentJob) {
329+
$failureMessage = 'Worker process terminated by signal (SIGTERM) - job execution interrupted due to timeout or manual termination';
330+
$this->QueuedJobs->markJobFailed($this->currentJob, $failureMessage);
331+
$this->logError('Job ' . $this->currentJob->job_task . ' (id ' . $this->currentJob->id . ') failed due to worker termination', $this->pid);
332+
$this->io->out('Current job marked as failed due to worker termination.');
333+
}
321334
$this->exit = true;
322335
}
323336

0 commit comments

Comments
 (0)