1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JMS\JobQueueBundle\Command; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManager; |
6
|
|
|
use Doctrine\Persistence\ManagerRegistry as PersistenceManagerRegistry; |
7
|
|
|
use JMS\JobQueueBundle\Entity\Job; |
8
|
|
|
use Symfony\Component\Console\Command\Command; |
9
|
|
|
use JMS\JobQueueBundle\Entity\Repository\JobManager; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
12
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
13
|
|
|
|
14
|
|
|
class MarkJobIncompleteCommand extends Command |
15
|
|
|
{ |
16
|
|
|
protected static $defaultName = 'jms-job-queue:mark-incomplete'; |
17
|
|
|
|
18
|
|
|
private $registry; |
19
|
|
|
private $jobManager; |
20
|
|
|
|
21
|
|
|
public function __construct(PersistenceManagerRegistry $managerRegistry, JobManager $jobManager) |
22
|
|
|
{ |
23
|
|
|
$this->registry = $managerRegistry; |
24
|
|
|
$this->jobManager = $jobManager; |
25
|
|
|
|
26
|
|
|
parent::__construct(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
protected function configure() |
30
|
|
|
{ |
31
|
|
|
$this |
32
|
|
|
->setDescription('Internal command (do not use). It marks jobs as incomplete.') |
33
|
|
|
->addArgument('job-id', InputArgument::REQUIRED, 'The ID of the Job.'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
37
|
|
|
{ |
38
|
|
|
/** @var EntityManager $em */ |
39
|
|
|
$em = $this->registry->getManagerForClass(Job::class); |
40
|
|
|
|
41
|
|
|
/** @var Job|null $job */ |
42
|
|
|
$job = $em->createQuery("SELECT j FROM " . Job::class . " j WHERE j.id = :id") |
43
|
|
|
->setParameter('id', $input->getArgument('job-id')) |
44
|
|
|
->getOneOrNullResult(); |
45
|
|
|
|
46
|
|
|
if ($job === null) { |
47
|
|
|
$output->writeln('<error>Job was not found.</error>'); |
48
|
|
|
|
49
|
|
|
return Command::FAILURE; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$this->jobManager->closeJob($job, Job::STATE_INCOMPLETE); |
53
|
|
|
|
54
|
|
|
return Command::SUCCESS; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|