Skip to content

Commit 70247b6

Browse files
committed
[TASK] do not allow createing a job if one is running or waiting
1 parent 38ac7a0 commit 70247b6

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

Classes/Command/JobCreatorCommand.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use B13\ContentSync\Domain\Model\Job;
1717
use B13\ContentSync\Domain\Repository\JobRepository;
1818
use B13\ContentSync\Domain\Validation\ConfigurationValidator;
19+
use B13\ContentSync\Exception;
1920
use Symfony\Component\Console\Attribute\AsCommand;
2021
use Symfony\Component\Console\Command\Command;
2122
use Symfony\Component\Console\Input\InputInterface;
@@ -40,7 +41,12 @@ public function execute(InputInterface $input, OutputInterface $output): int
4041
$this->validator->assertValid($configuration);
4142
$job = new Job();
4243
$job->setConfiguration($configuration);
43-
$this->jobRepository->add($job);
44+
try {
45+
$this->jobRepository->add($job);
46+
} catch (Exception $e) {
47+
$output->writeln($e->getMessage());
48+
return Command::FAILURE;
49+
}
4450
return 0;
4551
}
4652
}

Classes/Domain/Repository/JobRepository.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414

1515
use B13\ContentSync\Domain\Model\Job;
16+
use B13\ContentSync\Exception;
1617
use TYPO3\CMS\Core\Database\Connection;
1718
use TYPO3\CMS\Core\Database\ConnectionPool;
1819

@@ -26,6 +27,14 @@ public function __construct(
2627

2728
public function add(Job $job): void
2829
{
30+
$waitingJob = $this->findOneWaiting();
31+
if ($waitingJob !== null) {
32+
throw new Exception('there is already a waiting job', 1780465898);
33+
}
34+
$runningJob = $this->findOneRunning();
35+
if ($runningJob !== null) {
36+
throw new Exception('there is already a running job', 1780465899);
37+
}
2938
$this->connectionPool->getConnectionForTable(self::TABLE)->insert(self::TABLE, $job->toDatabaseRow());
3039
}
3140

0 commit comments

Comments
 (0)