Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Job will not get state 'Finished' if ->setOriginalJob is used. #201

Open
SymenTimmermans opened this issue Feb 15, 2018 · 0 comments
Open

Comments

@SymenTimmermans
Copy link

SymenTimmermans commented Feb 15, 2018

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:

            $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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant