diff --git a/src/Command/Queue/FixCommand.php b/src/Command/Queue/FixCommand.php index eaca3fc..fff9244 100644 --- a/src/Command/Queue/FixCommand.php +++ b/src/Command/Queue/FixCommand.php @@ -39,8 +39,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int $scheduler = new Scheduler(); $scheduler->cleanupOrphanedJobs(); $scheduler->purgeBrokenQueueRecords(); - $scheduler->initializeScheduling(); + // Delete orphaned jobs (job rows with no matching schedule entry) before + // initializeScheduling() runs, so it correctly sees their runtemplates as + // missing a job and resets next_schedule instead of finding the + // soon-to-be-deleted orphan and leaving next_schedule stuck. $jobModel = new \MultiFlexi\Job(); $orphanedJobs = $jobModel->listingQuery() ->where('job.begin IS NULL') @@ -62,6 +65,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int ); } + $scheduler->initializeScheduling(); + $messages = []; foreach ($scheduler->getStatusMessages() as $message) { diff --git a/src/Command/QueueCommand.php b/src/Command/QueueCommand.php index 630a99f..f37c1a0 100644 --- a/src/Command/QueueCommand.php +++ b/src/Command/QueueCommand.php @@ -456,10 +456,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int $scheduler = new Scheduler(); $scheduler->cleanupOrphanedJobs(); $scheduler->purgeBrokenQueueRecords(); - $scheduler->initializeScheduling(); - // Delete orphaned jobs: jobs that haven't started, haven't finished, - // and have no corresponding entry in the schedule table. + // Delete orphaned jobs (job rows with no matching schedule entry) before + // initializeScheduling() runs, so it correctly sees their runtemplates as + // missing a job and resets next_schedule instead of finding the + // soon-to-be-deleted orphan and leaving next_schedule stuck. // These jobs are stuck and will never execute. $jobModel = new \MultiFlexi\Job(); $orphanedJobs = $jobModel->listingQuery() @@ -482,6 +483,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int ); } + $scheduler->initializeScheduling(); + $messages = []; foreach ($scheduler->getStatusMessages() as $message) {