From 61fc1f340c72b3eeaaea7f990e8b2a62da9fce94 Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Mon, 1 Mar 2021 20:28:04 +0100 Subject: [PATCH] merged pull requests #181 #183 #187 --- .gitignore | 1 - Command/ExecuteCommand.php | 17 ++++++++++++++--- Resources/views/Detail/index.html.twig | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 5f1065c9..0e876910 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ vendor/ composer.lock build/ -.coveralls.yml .php_cs.cache .phpcs-cache .phpunit.result.cache diff --git a/Command/ExecuteCommand.php b/Command/ExecuteCommand.php index 854fcd7a..026ea2d7 100644 --- a/Command/ExecuteCommand.php +++ b/Command/ExecuteCommand.php @@ -118,11 +118,14 @@ protected function execute(InputInterface $input, OutputInterface $output) $noneExecution = true; foreach ($commands as $command) { - $this->em->refresh($this->em->find(ScheduledCommand::class, $command)); + + // PullRequest: fix command refresh #183 + $command = $this->em->find(ScheduledCommand::class, $command->getId()); + if ($command->isDisabled() || $command->isLocked()) { continue; } - + $scheduledCommand = $this->em->find(ScheduledCommand::class, $scheduledCommand); /** @var ScheduledCommand $command */ $cron = CronExpression::factory($command->getCronExpression()); $nextRunDate = $cron->getNextRunDate($command->getLastExecution()); @@ -183,7 +186,10 @@ private function executeCommand(ScheduledCommand $scheduledCommand, OutputInterf $this->em->persist($scheduledCommand); $this->em->flush(); $this->em->getConnection()->commit(); - } catch (\Exception $e) { + // PullRequest: Clear ORM after run scheduled command #187 + $this->em->clear(); + } catch (\Throwable $e) { + $this->em->getConnection()->rollBack(); $output->writeln( sprintf( @@ -249,6 +255,11 @@ private function executeCommand(ScheduledCommand $scheduledCommand, OutputInterf $this->em = $this->em->create($this->em->getConnection(), $this->em->getConfiguration()); } + // Reactivate the command in DB + + // PullRequest: Fix repeated jobs #181 + $scheduledCommand = $this->em->find(ScheduledCommand::class, $scheduledCommand); + $scheduledCommand->setLastReturnCode($result); $scheduledCommand->setLocked(false); $scheduledCommand->setExecuteImmediately(false); diff --git a/Resources/views/Detail/index.html.twig b/Resources/views/Detail/index.html.twig index f99b13b9..1e39364a 100644 --- a/Resources/views/Detail/index.html.twig +++ b/Resources/views/Detail/index.html.twig @@ -30,7 +30,7 @@ {# Form's actions #}
- Cancel + {{ 'action.cancel'|trans }} {{ form_widget( scheduledCommandForm.save, {'attr': {'class': 'btn btn-success btn-lg pull-right'} } ) }}
{{ form_end( scheduledCommandForm ) }}