I tried implementing a way to link 'retry' jobs if previous jobs fail.
When a user requests an entity to be processed, my script checks if related jobs to the entity can be found.
In this case it will find a failed job. I would like to link the failed job to a new job, but I can't seem to use 'addRetryJob', since this needs a 'running' job. So I use 'setOriginalJob'. My code looks somewhat like this:
$job = $em->getRepository('JMSJobQueueBundle:Job')
->findJobForRelatedEntity('command', $entity);
if ($job) {
if ($job->isRunning() ||
$job->isPending() ||
$job->isFinished()) {
// do nothing
} else if ($job->isCanceled() ||
$job->isFailed() ||
$job->isIncomplete()) {
$retryJob = true;
}
} else {
$startNewJob = true;
}
if ($startNewJob || $retryJob) {
$njob = new Job('command', array($id));
$njob->addRelatedEntity($entity);
if ($retryJob) {
$njob->setOriginalJob($job);
}
$em->persist($njob);
$em->flush();
}
This results in two issues:
The new Job is not seen on the overview page.
The new Job will start, and complete, but will keep the state 'running'.
Maybe there's a flaw in my implementation, would love to hear about it.
I'm using version 1.4.2, on Symfony 2.6.
I tried implementing a way to link 'retry' jobs if previous jobs fail.
When a user requests an entity to be processed, my script checks if related jobs to the entity can be found. In this case it will find a failed job. I would like to link the failed job to a new job, but I can't seem to use 'addRetryJob', since this needs a 'running' job. So I use 'setOriginalJob'. My code looks somewhat like this:
This results in two issues:
Maybe there's a flaw in my implementation, would love to hear about it.