diff --git a/pkg/job-queue/JobRunner.php b/pkg/job-queue/JobRunner.php index 17a51b110..afd445c67 100644 --- a/pkg/job-queue/JobRunner.php +++ b/pkg/job-queue/JobRunner.php @@ -51,7 +51,16 @@ public function runUnique($ownerId, $name, callable $runCallback) try { $result = call_user_func($runCallback, $jobRunner, $childJob); } catch (\Throwable $e) { - $this->jobProcessor->failChildJob($childJob); + try { + $this->jobProcessor->failChildJob($childJob); + } catch (\Throwable $t) { + throw new OrphanJobException(sprintf( + 'Job cleanup failed. ID: "%s" Name: "%s"', + $childJob->getId(), + $childJob->getName() + ), 0, $e); + } + throw $e; } diff --git a/pkg/job-queue/OrphanJobException.php b/pkg/job-queue/OrphanJobException.php new file mode 100644 index 000000000..37eac5ca7 --- /dev/null +++ b/pkg/job-queue/OrphanJobException.php @@ -0,0 +1,7 @@ +createJobProcessorMock(); + $jobProcessor + ->expects($this->once()) + ->method('findOrCreateRootJob') + ->will($this->returnValue($root)) + ; + $jobProcessor + ->expects($this->once()) + ->method('findOrCreateChildJob') + ->will($this->returnValue($child)) + ; + $jobProcessor + ->expects($this->never()) + ->method('successChildJob') + ; + $jobProcessor + ->expects($this->once()) + ->method('failChildJob') + ->willThrowException(new \Exception()) + ; + + $jobRunner = new JobRunner($jobProcessor); + $this->expectException(OrphanJobException::class); + $jobRunner->runUnique('owner-id', 'job-name', function () { + throw new \Exception(); + }); + } + public function testRunUniqueShouldNotSuccessJobIfJobIsAlreadyStopped() { $root = new Job();