Skip to content

Commit 9bf4712

Browse files
committed
Add timeout handling.
1 parent db803df commit 9bf4712

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
@@ -74,6 +74,11 @@ class Processor {
7474
*/
7575
protected QueueProcessesTable $QueueProcesses;
7676

77+
/**
78+
* @var \Queue\Model\Entity\QueuedJob|null
79+
*/
80+
protected ?QueuedJob $currentJob = null;
81+
7782
/**
7883
* @param \Queue\Console\Io $io
7984
* @param \Psr\Log\LoggerInterface $logger
@@ -197,6 +202,7 @@ public function run(array $args): int {
197202
* @return void
198203
*/
199204
protected function runJob(QueuedJob $queuedJob, string $pid): void {
205+
$this->currentJob = $queuedJob;
200206
$this->io->out('Running Job of type "' . $queuedJob->job_task . '"');
201207
$this->log('job ' . $queuedJob->job_task . ', id ' . $queuedJob->id, $pid, false);
202208
$taskName = $queuedJob->job_task;
@@ -235,6 +241,7 @@ protected function runJob(QueuedJob $queuedJob, string $pid): void {
235241

236242
$this->QueuedJobs->markJobDone($queuedJob);
237243
$this->io->out('Job Finished.');
244+
$this->currentJob = null;
238245
}
239246

240247
/**
@@ -307,6 +314,12 @@ protected function getTaskConf(): array {
307314
* @return void
308315
*/
309316
protected function exit(int $signal): void {
317+
if ($this->currentJob) {
318+
$failureMessage = 'Worker process terminated by signal (SIGTERM) - job execution interrupted due to timeout or manual termination';
319+
$this->QueuedJobs->markJobFailed($this->currentJob, $failureMessage);
320+
$this->logError('Job ' . $this->currentJob->job_task . ' (id ' . $this->currentJob->id . ') failed due to worker termination', $this->pid);
321+
$this->io->out('Current job marked as failed due to worker termination.');
322+
}
310323
$this->exit = true;
311324
}
312325

0 commit comments

Comments
 (0)