@@ -118,11 +118,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
118
118
119
119
$ noneExecution = true ;
120
120
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
+
122
125
if ($ command ->isDisabled () || $ command ->isLocked ()) {
123
126
continue ;
124
127
}
125
-
128
+ $ scheduledCommand = $ this -> em -> find (ScheduledCommand::class, $ scheduledCommand );
126
129
/** @var ScheduledCommand $command */
127
130
$ cron = CronExpression::factory ($ command ->getCronExpression ());
128
131
$ nextRunDate = $ cron ->getNextRunDate ($ command ->getLastExecution ());
@@ -183,7 +186,10 @@ private function executeCommand(ScheduledCommand $scheduledCommand, OutputInterf
183
186
$ this ->em ->persist ($ scheduledCommand );
184
187
$ this ->em ->flush ();
185
188
$ 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
+
187
193
$ this ->em ->getConnection ()->rollBack ();
188
194
$ output ->writeln (
189
195
sprintf (
@@ -249,6 +255,11 @@ private function executeCommand(ScheduledCommand $scheduledCommand, OutputInterf
249
255
$ this ->em = $ this ->em ->create ($ this ->em ->getConnection (), $ this ->em ->getConfiguration ());
250
256
}
251
257
258
+ // Reactivate the command in DB
259
+
260
+ // PullRequest: Fix repeated jobs #181
261
+ $ scheduledCommand = $ this ->em ->find (ScheduledCommand::class, $ scheduledCommand );
262
+
252
263
$ scheduledCommand ->setLastReturnCode ($ result );
253
264
$ scheduledCommand ->setLocked (false );
254
265
$ scheduledCommand ->setExecuteImmediately (false );
0 commit comments