CommandSchedulerBundle
CommandSchedulerBundle copied to clipboard
Schedule task is being repeated if locked
After a recent migration to the last version, if one task is locked, this is being inserted again in the task list (screenshot attached)
Any possible workaround to found this bug/issue?
Got the same issue
same story
I've done a quick fix by setting command
as a unique field in the database
It seems that the entityManager gets confused and tries to INSERT a new row instead of UPDATE'ing the correct one. Setting "command" as a unique field in the database is NOT the solution: the executeCommand fails with a duplicate key exception, so even if it doesn't mess the database up by creating a new entry, it doesn't unlock the right entry as well.
It seems to work if we retrieve the scheduledCommand instance from the database just before unlocking it:
--- vendor/jmose/command-scheduler-bundle/Command/ExecuteCommand.php.orig 2020-10-21 00:40:33.467171379 +0200
+++ vendor/jmose/command-scheduler-bundle/Command/ExecuteCommand.php 2020-10-21 00:38:22.263744598 +0200
@@ -249,6 +249,7 @@
$this->em = $this->em->create($this->em->getConnection(), $this->em->getConfiguration());
}
+ $scheduledCommand = $this->em->find(ScheduledCommand::class, $scheduledCommand);
$scheduledCommand->setLastReturnCode($result);
$scheduledCommand->setLocked(false);
$scheduledCommand->setExecuteImmediately(false);
Thanks, I've made a pull request for it #181. Your solution is of course better.
This started happening in my case after I added $this->entityManager->clear();
inside my command which is executed, so this seems related.