aboutsummaryrefslogtreecommitdiffstats
path: root/core/BackgroundJobs/AsyncProcessJob.php
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2025-04-28 19:57:56 -0100
committerMaxence Lange <maxence@artificial-owl.com>2025-04-28 19:58:06 -0100
commit6d272ff894fa969e5a526caf6a91d60eda115c53 (patch)
treedf90f826a29f7169dd9b550f2e478a1b09d29e71 /core/BackgroundJobs/AsyncProcessJob.php
parent10a01423ecfc7e028960eee8058bd177ad28d484 (diff)
downloadnextcloud-server-enh/noid/async-process-run.tar.gz
nextcloud-server-enh/noid/async-process-run.zip
feat(async): AsyncProcessenh/noid/async-process-run
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'core/BackgroundJobs/AsyncProcessJob.php')
-rw-r--r--core/BackgroundJobs/AsyncProcessJob.php62
1 files changed, 62 insertions, 0 deletions
diff --git a/core/BackgroundJobs/AsyncProcessJob.php b/core/BackgroundJobs/AsyncProcessJob.php
new file mode 100644
index 00000000000..3fd43abf5ab
--- /dev/null
+++ b/core/BackgroundJobs/AsyncProcessJob.php
@@ -0,0 +1,62 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OC\Core\BackgroundJobs;
+
+use OC\Async\Db\BlockMapper;
+use OC\Async\ForkManager;
+use OC\Async\Wrappers\LoggerBlockWrapper;
+use OC\Config\Lexicon\CoreConfigLexicon;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\Async\Enum\ProcessExecutionTime;
+use OCP\BackgroundJob\TimedJob;
+use OCP\IAppConfig;
+
+class AsyncProcessJob extends TimedJob {
+ public function __construct(
+ ITimeFactory $time,
+ private IAppConfig $appConfig,
+ private ForkManager $forkManager,
+ private BlockMapper $blockMapper,
+ private LoggerBlockWrapper $loggerProcessWrapper,
+ ) {
+ parent::__construct($time);
+
+ $this->setTimeSensitivity(self::TIME_SENSITIVE);
+// $this->setInterval(60 * 5);
+ $this->setInterval(1);
+ }
+
+ protected function run(mixed $argument): void {
+ $this->discoverLoopAddress();
+
+ $this->forkManager->setWrapper($this->loggerProcessWrapper);
+
+ $this->blockMapper->resetFailedBlock();
+
+ $metadata = ['executionTime' => ProcessExecutionTime::LATER];
+ foreach ($this->blockMapper->getSessionOnStandBy() as $session) {
+ $this->forkManager->forkSession($session, $metadata);
+ }
+
+ $this->blockMapper->removeSuccessfulBlock();
+
+ $this->forkManager->waitChildProcess();
+ }
+
+ private function discoverLoopAddress(): void {
+ if ($this->appConfig->hasKey('core', CoreConfigLexicon::ASYNC_LOOPBACK_ADDRESS, true)) {
+ return;
+ }
+
+ $found = $this->forkManager->discoverLoopbackEndpoint();
+ if ($found !== null) {
+ $this->appConfig->setValueString('core', CoreConfigLexicon::ASYNC_LOOPBACK_ADDRESS, $found);
+ }
+ }
+}