Skip to content

Commit

Permalink
feat: refresh entity before set to stale
Browse files Browse the repository at this point in the history
  • Loading branch information
rugbymauri committed Aug 22, 2023
1 parent fcc782e commit e07f3db
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Command/CheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(protected ExecutionManager $executionManager)

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->executionManager->check();
$this->executionManager->check(15);

return Command::SUCCESS;
}
Expand Down
1 change: 1 addition & 0 deletions src/Command/ExecuteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
// Create execution
$execution = new Execution();
$execution->setJob($cronJob::class)
->setState(Execution::STATE_RUNNING)
->setCommand($command);
$this->entityManager->persist($execution);
$this->entityManager->flush($execution);
Expand Down
13 changes: 8 additions & 5 deletions src/Manager/ExecutionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,14 @@ protected function cleanupStale(): void
foreach ($executions as $execution) {
$this->logger->debug(sprintf('Checking execution state with id %d. (%s)', $execution->getPid(), $execution->getJob()));
if (! posix_kill($execution->getPid(), 0)) {
$this->logger->warning(sprintf('Marking execution with id %d as stale. (%s)', $execution->getPid(), $execution->getJob()));
$execution
->setState(Execution::STATE_STALE)
->setPid(null);
$this->em->flush($execution);
$this->em->refresh($execution);
if ($execution->getState() === Execution::STATE_RUNNING) {
$this->logger->warning(sprintf('Marking execution with id %d as stale. (%s)', $execution->getPid(), $execution->getJob()));
$execution
->setState(Execution::STATE_STALE)
->setPid(null);
$this->em->flush($execution);
}
}
}
}
Expand Down

0 comments on commit e07f3db

Please sign in to comment.