Skip to content

Commit 1ff3441

Browse files
authored
Merge pull request #683 from nextcloud/feat/taskprocessing-trigger-endpoint
feat: Implement ITriggerableProvider for task processing providers
2 parents 83d5152 + b43d5f4 commit 1ff3441

File tree

5 files changed

+49
-3
lines changed

5 files changed

+49
-3
lines changed

lib/Controller/TaskProcessingController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
use OCA\AppAPI\AppInfo\Application;
1313
use OCA\AppAPI\Attribute\AppAPIAuth;
14+
use OCA\AppAPI\Service\AppAPIService;
15+
use OCA\AppAPI\Service\ExAppService;
1416
use OCA\AppAPI\Service\ProvidersAI\TaskProcessingService;
1517
use OCP\AppFramework\Http;
1618
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
@@ -26,10 +28,14 @@ class TaskProcessingController extends OCSController {
2628
public function __construct(
2729
IRequest $request,
2830
private readonly TaskProcessingService $taskProcessingService,
31+
private readonly AppAPIService $appAPIService,
32+
private readonly ExAppService $exAppService,
2933
) {
3034
parent::__construct(Application::APP_ID, $request);
3135

3236
$this->request = $request;
37+
$this->taskProcessingService->setAppAPIService($this->appAPIService);
38+
$this->taskProcessingService->setExAppService($this->exAppService);
3339
}
3440

3541
#[NoCSRFRequired]

lib/Listener/GetTaskProcessingProvidersListener.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
namespace OCA\AppAPI\Listener;
1111

1212
use JsonException;
13+
use OCA\AppAPI\Service\AppAPIService;
14+
use OCA\AppAPI\Service\ExAppService;
1315
use OCA\AppAPI\Service\ProvidersAI\TaskProcessingService;
1416
use OCP\EventDispatcher\Event;
1517
use OCP\EventDispatcher\IEventListener;
@@ -19,6 +21,8 @@
1921
class GetTaskProcessingProvidersListener implements IEventListener {
2022
public function __construct(
2123
private readonly TaskProcessingService $taskProcessingService,
24+
private readonly ExAppService $exAppService,
25+
private readonly AppAPIService $appAPIService,
2226
private readonly LoggerInterface $logger,
2327
) {
2428
}
@@ -32,13 +36,15 @@ public function handle(Event $event): void {
3236
return;
3337
}
3438

39+
$this->taskProcessingService->setExAppService($this->exAppService);
40+
$this->taskProcessingService->setAppAPIService($this->appAPIService);
3541
$exAppsProviders = $this->taskProcessingService->getRegisteredTaskProcessingProviders();
3642

3743
foreach ($exAppsProviders as $exAppProvider) {
3844
try {
3945
// Decode provider data
4046
$providerData = json_decode($exAppProvider->getProvider(), true, 512, JSON_THROW_ON_ERROR);
41-
$providerInstance = $this->taskProcessingService->getAnonymousExAppProvider($providerData);
47+
$providerInstance = $this->taskProcessingService->getAnonymousExAppProvider($providerData, $exAppProvider->getAppId());
4248
$event->addProvider($providerInstance);
4349

4450
// Decode and add custom task type if it exists

lib/Service/AppAPIService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function __construct(
5252
private readonly HarpService $harpService,
5353
) {
5454
$this->client = $clientService->newClient();
55+
$this->exAppService->setAppAPIService($this);
5556
}
5657

5758
/**

lib/Service/ExAppService.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
class ExAppService {
3838
private ?ICache $cache = null;
39+
private AppAPIService $appAPIService;
3940

4041
public function __construct(
4142
private readonly LoggerInterface $logger,
@@ -66,6 +67,7 @@ public function __construct(
6667
$this->cache = $cacheFactory->createDistributed(Application::APP_ID . '/service');
6768
}
6869
}
70+
$this->taskProcessingService->setExAppService($this);
6971
}
7072

7173
public function getExApp(string $appId): ?ExApp {
@@ -446,4 +448,9 @@ private function unregisterExAppWebhooks(string $appId): void {
446448
$this->logger->debug(sprintf('Error while unregistering ExApp %s webhooks: %s', $appId, $e->getMessage()));
447449
}
448450
}
451+
452+
public function setAppAPIService(AppAPIService $appAPIService): void {
453+
$this->appAPIService = $appAPIService;
454+
$this->taskProcessingService->setAppAPIService($this->appAPIService);
455+
}
449456
}

lib/Service/ProvidersAI/TaskProcessingService.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use OCA\AppAPI\AppInfo\Application;
1414
use OCA\AppAPI\Db\TaskProcessing\TaskProcessingProvider;
1515
use OCA\AppAPI\Db\TaskProcessing\TaskProcessingProviderMapper;
16+
use OCA\AppAPI\Service\AppAPIService;
17+
use OCA\AppAPI\Service\ExAppService;
1618
use OCP\AppFramework\Bootstrap\IRegistrationContext;
1719
use OCP\AppFramework\Db\DoesNotExistException;
1820
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
@@ -23,6 +25,7 @@
2325
use OCP\TaskProcessing\EShapeType;
2426
use OCP\TaskProcessing\IProvider;
2527
use OCP\TaskProcessing\ITaskType;
28+
use OCP\TaskProcessing\ITriggerableProvider;
2629
use OCP\TaskProcessing\ShapeDescriptor;
2730
use OCP\TaskProcessing\ShapeEnumValue;
2831
use Psr\Log\LoggerInterface;
@@ -31,6 +34,9 @@ class TaskProcessingService {
3134
private ?ICache $cache = null;
3235
private ?array $registeredProviders = null;
3336

37+
private AppAPIService $appAPIService;
38+
private ExAppService $exAppService;
39+
3440
public function __construct(
3541
ICacheFactory $cacheFactory,
3642
private readonly TaskProcessingProviderMapper $mapper,
@@ -41,6 +47,14 @@ public function __construct(
4147
}
4248
}
4349

50+
public function setAppAPIService(AppAPIService $appAPIService): void {
51+
$this->appAPIService = $appAPIService;
52+
}
53+
54+
public function setExAppService(ExAppService $exAppService): void {
55+
$this->exAppService = $exAppService;
56+
}
57+
4458
/**
4559
* Get list of registered TaskProcessing providers (only for enabled ExApps)
4660
*
@@ -241,7 +255,7 @@ public function registerExAppTaskProcessingProviders(IRegistrationContext $conte
241255
$className = '\\OCA\\AppAPI\\' . $exAppProvider->getAppId() . '\\' . $exAppProvider->getName();
242256

243257
try {
244-
$provider = $this->getAnonymousExAppProvider(json_decode($exAppProvider->getProvider(), true, flags: JSON_THROW_ON_ERROR));
258+
$provider = $this->getAnonymousExAppProvider(json_decode($exAppProvider->getProvider(), true, flags: JSON_THROW_ON_ERROR), $exAppProvider->getAppId());
245259
} catch (JsonException $e) {
246260
$this->logger->debug('Failed to register ExApp TaskProcessing provider', ['exAppId' => $exAppProvider->getAppId(), 'taskType' => $exAppProvider->getName(), 'exception' => $e]);
247261
continue;
@@ -261,10 +275,14 @@ public function registerExAppTaskProcessingProviders(IRegistrationContext $conte
261275
*/
262276
public function getAnonymousExAppProvider(
263277
array $provider,
278+
string $appId,
264279
): IProvider {
265-
return new class($provider) implements IProvider {
280+
return new class($provider, $appId, $this->exAppService, $this->appAPIService) implements IProvider, ITriggerableProvider {
266281
public function __construct(
267282
private readonly array $provider,
283+
private readonly string $appId,
284+
private readonly ExAppService $exAppService,
285+
private readonly AppAPiService $appAPIService
268286
) {
269287
}
270288

@@ -280,6 +298,14 @@ public function getTaskTypeId(): string {
280298
return $this->provider['task_type'];
281299
}
282300

301+
public function trigger(): void {
302+
$exApp = $this->exAppService->getExApp($this->appId);
303+
if ($exApp === null) {
304+
return;
305+
}
306+
$this->appAPIService->requestToExApp($exApp, '/trigger?' . http_build_query(['providerId' => $this->provider['id']]));
307+
}
308+
283309
public function getExpectedRuntime(): int {
284310
return $this->provider['expected_runtime'];
285311
}

0 commit comments

Comments
 (0)