forked from schmittjoh/JMSJobQueueBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMarkJobIncompleteCommand.php
More file actions
67 lines (53 loc) · 1.91 KB
/
MarkJobIncompleteCommand.php
File metadata and controls
67 lines (53 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace JMS\JobQueueBundle\Command;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\ORM\EntityManager;
use JMS\JobQueueBundle\Entity\Job;
use Symfony\Component\Console\Command\Command;
use JMS\JobQueueBundle\Entity\Repository\JobManager;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
class MarkJobIncompleteCommand extends Command
{
public const COMMAND_NAME = 'jms-job-queue:mark-incomplete';
private ManagerRegistry $registry;
private JobManager $jobManager;
public function __construct(ManagerRegistry $managerRegistry, JobManager $jobManager)
{
parent::__construct(self::COMMAND_NAME);
$this->registry = $managerRegistry;
$this->jobManager = $jobManager;
}
public static function getDefaultName(): string
{
return self::COMMAND_NAME;
}
protected function configure(): void
{
$this
->setDescription('Internal command (do not use). It marks jobs as incomplete.')
->addArgument('job-id', InputArgument::REQUIRED, 'The ID of the Job.')
;
}
/**
* @throws NonUniqueResultException
* @throws \Exception
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
/** @var EntityManager $em */
$em = $this->registry->getManagerForClass(Job::class);
/** @var Job|null $job */
$job = $em->createQuery("SELECT j FROM ".Job::class." j WHERE j.id = :id")
->setParameter('id', $input->getArgument('job-id'))
->getOneOrNullResult();
if ($job === null) {
$output->writeln('<error>Job was not found.</error>');
return 1;
}
$this->jobManager->closeJob($job, Job::STATE_INCOMPLETE);
return 0;
}
}