Pārlūkot izejas kodu

fix(bg-jobs): Remove interval bookkeeping

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Marcel Klehr 5 mēneši atpakaļ
vecāks
revīzija
993398b88a
1 mainītis faili ar 1 papildinājumiem un 36 dzēšanām
  1. 1 36
      core/Command/Background/JobWorker.php

+ 1 - 36
core/Command/Background/JobWorker.php

@@ -71,37 +71,21 @@ class JobWorker extends JobBase {
 			return 1;
 		}
 
-		$interval = (int)($input->getOption('interval') ?? 5);
-
 		while (true) {
 			// Handle canceling of the process
 			try {
 				$this->abortIfInterrupted();
 			} catch (InterruptedException $e) {
-				$output->writeln('<comment>Cleaning up before quitting. Press Ctrl-C again to kill, but this may have unexpected side effects.</comment>');
-				$this->unlockExecuted();
 				$output->writeln('<info>Background job worker stopped</info>');
 				break;
 			}
 
 			$this->printSummary($input, $output);
 
-			// Unlock jobs that should be executed again after the interval
-			// Alternative could be to set last_checked to interval in the future to avoid the extra locks
-			foreach ($this->executedJobs as $id => $time) {
-				if ($time <= time() - $interval) {
-					unset($this->executedJobs[$id]);
-					$job = $this->jobList->getById($id);
-					if ($job !== null) {
-						$this->jobList->unlockJob($job);
-					}
-				}
-			}
-
 			usleep(50000);
 			$job = $this->jobList->getNext(false, $jobClass);
 			if (!$job) {
-				if ($input->getOption('once') === true || $interval === 0) {
+				if ($input->getOption('once') === true) {
 					break;
 				}
 
@@ -111,12 +95,6 @@ class JobWorker extends JobBase {
 				continue;
 			}
 
-
-			if (isset($this->executedJobs[$job->getId()]) && ($this->executedJobs[$job->getId()] + $interval > time())) {
-				$output->writeln("<comment>Job already executed within timeframe " . get_class($job) . " " . $job->getId() . '</comment>', OutputInterface::VERBOSITY_VERBOSE);
-				continue;
-			}
-
 			$output->writeln("Running job " . get_class($job) . " with ID " . $job->getId());
 
 			if ($output->isVerbose()) {
@@ -131,15 +109,12 @@ class JobWorker extends JobBase {
 
 			$this->jobList->setLastJob($job);
 			$this->jobList->unlockJob($job);
-			$this->executedJobs[$job->getId()] = time();
 
 			if ($input->getOption('once') === true) {
 				break;
 			}
 		}
 
-		$this->unlockExecuted();
-
 		return 0;
 	}
 
@@ -155,14 +130,4 @@ class JobWorker extends JobBase {
 		}
 		$this->writeTableInOutputFormat($input, $output, $counts);
 	}
-
-	private function unlockExecuted() {
-		foreach ($this->executedJobs as $id => $time) {
-			unset($this->executedJobs[$id]);
-			$job = $this->jobList->getById($id);
-			if ($job !== null) {
-				$this->jobList->unlockJob($job);
-			}
-		}
-	}
 }