Skip to content

Commit

Permalink
merged pull requests j-guyon#181 j-guyon#183 j-guyon#187
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris53897 committed Mar 1, 2021
1 parent f1e50c8 commit 61fc1f3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
vendor/
composer.lock
build/
.coveralls.yml
.php_cs.cache
.phpcs-cache
.phpunit.result.cache
Expand Down
17 changes: 14 additions & 3 deletions Command/ExecuteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/Detail/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

{# Form's actions #}
<div class="row">
<a href="{{ path('jmose_command_scheduler_list') }}" class="btn btn-default btn-lg" role="button">Cancel</a>
<a href="{{ path('jmose_command_scheduler_list') }}" class="btn btn-default btn-lg" role="button">{{ 'action.cancel'|trans }}</a>
{{ form_widget( scheduledCommandForm.save, {'attr': {'class': 'btn btn-success btn-lg pull-right'} } ) }}
</div>
{{ form_end( scheduledCommandForm ) }}
Expand Down

0 comments on commit 61fc1f3

Please sign in to comment.