4.0.0 org.codehaus.sonar sonar 4.2-SNAPSHOT sonar-core SonarQube :: Core Core components shared to batch and server com.google.code.findbugs jsr305 provided ${project.groupId} sonar-plugin-api classworlds classworlds org.mybatis mybatis org.codehaus.sonar sonar-update-center-common org.codehaus.sonar sonar-home org.hibernate hibernate-core org.hibernate hibernate-annotations org.hibernate hibernate-commons-annotations org.hibernate hibernate-entitymanager geronimo-spec geronimo-spec-jta commons-dbcp commons-dbcp commons-dbutils commons-dbutils org.codehaus.plexus plexus-classworlds com.googlecode.json-simple json-simple com.tinkerpop.blueprints blueprints-core org.codehaus.jackson jackson-core-asl org.codehaus.jackson jackson-mapper-asl org.codehaus.jettison jettison colt colt org.slf4j slf4j-api ch.qos.logback logback-classic ch.qos.logback logback-core org.slf4j jcl-over-slf4j org.slf4j log4j-over-slf4j junit junit test org.mockito mockito-all test org.hamcrest hamcrest-all test org.dbunit dbunit test org.easytesting fest-assert test mysql mysql-connector-java test postgresql postgresql test net.sourceforge.jtds jtds test com.h2database h2 test org.apache.maven.plugins maven-jar-plugin test-jar run-mybatis-its org.apache.maven.plugins maven-surefire-plugin ${orchestrator.configUrl} com.oracle ojdbc6 11.2.0.3.0 test rashing_disabled_users_search'>artonge/fix/prevent_missing_users_from_crashing_disabled_users_search Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/TextToImage/TaskBackgroundJob.php
blob: 169900055304560ea43acb8b4bdc24ab2d6d46b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */


namespace OC\TextToImage;

use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\QueuedJob;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\TextToImage\Events\TaskFailedEvent;
use OCP\TextToImage\Events\TaskSuccessfulEvent;
use OCP\TextToImage\IManager;

class TaskBackgroundJob extends QueuedJob {
	public function __construct(
		ITimeFactory $timeFactory,
		private IManager $text2imageManager,
		private IEventDispatcher $eventDispatcher,
	) {
		parent::__construct($timeFactory);
		// We want to avoid overloading the machine with these jobs
		// so we only allow running one job at a time
		$this->setAllowParallelRuns(false);
	}

	/**
	 * @param array{taskId: int} $argument
	 * @inheritDoc
	 */
	protected function run($argument) {
		$taskId = $argument['taskId'];
		$task = $this->text2imageManager->getTask($taskId);
		try {
			$this->text2imageManager->runTask($task);
			$event = new TaskSuccessfulEvent($task);
		} catch (\Throwable $e) {
			$event = new TaskFailedEvent($task, $e->getMessage());
		}
		$this->eventDispatcher->dispatchTyped($event);
	}
}