CommandSchedulerBundle icon indicating copy to clipboard operation
CommandSchedulerBundle copied to clipboard

Schedule task is being repeated if locked

Open maikelreyes opened this issue 4 years ago • 6 comments

image 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?

maikelreyes avatar Aug 29 '20 11:08 maikelreyes

Got the same issue

alexandersch avatar Sep 16 '20 08:09 alexandersch

same story

bpastukh avatar Sep 16 '20 08:09 bpastukh

I've done a quick fix by setting command as a unique field in the database

alexandersch avatar Sep 16 '20 09:09 alexandersch

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);

armellin avatar Oct 20 '20 23:10 armellin

Thanks, I've made a pull request for it #181. Your solution is of course better.

alexandersch avatar Nov 03 '20 14:11 alexandersch

This started happening in my case after I added $this->entityManager->clear(); inside my command which is executed, so this seems related.

kovinet avatar Apr 09 '21 10:04 kovinet