@@ -118,11 +118,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
118118
119119 $ noneExecution = true ;
120120 foreach ($ commands as $ command ) {
121- $ this ->em ->refresh ($ this ->em ->find (ScheduledCommand::class, $ command ));
121+
122+ // PullRequest: fix command refresh #183
123+ $ command = $ this ->em ->find (ScheduledCommand::class, $ command ->getId ());
124+
122125 if ($ command ->isDisabled () || $ command ->isLocked ()) {
123126 continue ;
124127 }
125-
128+ $ scheduledCommand = $ this -> em -> find (ScheduledCommand::class, $ scheduledCommand );
126129 /** @var ScheduledCommand $command */
127130 $ cron = CronExpression::factory ($ command ->getCronExpression ());
128131 $ nextRunDate = $ cron ->getNextRunDate ($ command ->getLastExecution ());
@@ -183,7 +186,10 @@ private function executeCommand(ScheduledCommand $scheduledCommand, OutputInterf
183186 $ this ->em ->persist ($ scheduledCommand );
184187 $ this ->em ->flush ();
185188 $ this ->em ->getConnection ()->commit ();
186- } catch (\Exception $ e ) {
189+ // PullRequest: Clear ORM after run scheduled command #187
190+ $ this ->em ->clear ();
191+ } catch (\Throwable $ e ) {
192+
187193 $ this ->em ->getConnection ()->rollBack ();
188194 $ output ->writeln (
189195 sprintf (
@@ -249,6 +255,11 @@ private function executeCommand(ScheduledCommand $scheduledCommand, OutputInterf
249255 $ this ->em = $ this ->em ->create ($ this ->em ->getConnection (), $ this ->em ->getConfiguration ());
250256 }
251257
258+ // Reactivate the command in DB
259+
260+ // PullRequest: Fix repeated jobs #181
261+ $ scheduledCommand = $ this ->em ->find (ScheduledCommand::class, $ scheduledCommand );
262+
252263 $ scheduledCommand ->setLastReturnCode ($ result );
253264 $ scheduledCommand ->setLocked (false );
254265 $ scheduledCommand ->setExecuteImmediately (false );
0 commit comments