Skip to content

Commit c2f83f5

Browse files
committed
feat(task-streaming): rename ISynchronousOptionsProvider to ISynchronousOptionsAwareProvider
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent 8ea331c commit c2f83f5

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

lib/private/TaskProcessing/Manager.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use OCP\App\IAppManager;
2020
use OCP\AppFramework\Db\DoesNotExistException;
2121
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
22+
use OCP\AppFramework\Utility\ITimeFactory;
2223
use OCP\BackgroundJob\IJobList;
2324
use OCP\DB\Exception;
2425
use OCP\EventDispatcher\IEventDispatcher;
@@ -59,7 +60,7 @@
5960
use OCP\TaskProcessing\IInternalTaskType;
6061
use OCP\TaskProcessing\IManager;
6162
use OCP\TaskProcessing\IProvider;
62-
use OCP\TaskProcessing\ISynchronousOptionsProvider;
63+
use OCP\TaskProcessing\ISynchronousOptionsAwareProvider;
6364
use OCP\TaskProcessing\ISynchronousProvider;
6465
use OCP\TaskProcessing\ISynchronousWatermarkingProvider;
6566
use OCP\TaskProcessing\ITaskType;
@@ -158,6 +159,7 @@ public function __construct(
158159
private IUserSession $userSession,
159160
ICacheFactory $cacheFactory,
160161
private IFactory $l10nFactory,
162+
private ITimeFactory $timeFactory,
161163
) {
162164
$this->appData = $appDataFactory->get('core');
163165
$this->distributedCache = $cacheFactory->createDistributed('task_processing::');
@@ -1134,7 +1136,7 @@ public function processTask(Task $task, ISynchronousProvider $provider): bool {
11341136
$this->setTaskStatus($task, Task::STATUS_RUNNING);
11351137
if ($provider instanceof ISynchronousWatermarkingProvider) {
11361138
$output = $provider->process($task->getUserId(), $input, fn (float $progress) => $this->setTaskProgress($task->getId(), $progress), $task->getIncludeWatermark());
1137-
} elseif ($provider instanceof ISynchronousOptionsProvider) {
1139+
} elseif ($provider instanceof ISynchronousOptionsAwareProvider) {
11381140
$options = new SynchronousProviderOptions(
11391141
$task->getIncludeWatermark(),
11401142
$task->getPreferStreaming(),
@@ -1238,7 +1240,7 @@ public function setTaskIntermediateOutput(int $id, array $output): bool {
12381240
if ($userId !== null
12391241
&& $userId !== ''
12401242
&& $this->appManager->isEnabledForAnyone('notify_push')
1241-
&& class_exists('\OCA\NotifyPush\Queue\IQueue')
1243+
&& interface_exists('\OCA\NotifyPush\Queue\IQueue')
12421244
) {
12431245
try {
12441246
/** @psalm-suppress UndefinedClass */
@@ -1249,14 +1251,17 @@ public function setTaskIntermediateOutput(int $id, array $output): bool {
12491251
'message' => 'task_' . $task->getId(),
12501252
'body' => $output,
12511253
]);
1252-
// we don't update the DB if something was sent via notify_push
1253-
// so if the push messages are not received for some reason, the polling will still not see any intermediate output
1254-
// but will receive the final output
1255-
return true;
12561254
} catch (ContainerExceptionInterface|NotFoundExceptionInterface $e) {
12571255
$this->logger->debug('OCA\NotifyPush\IQueue not found, not sending to queue');
12581256
}
12591257
}
1258+
1259+
// throttle DB update
1260+
$now = $this->timeFactory->now()->getTimestamp();
1261+
if ($now - $task->getLastUpdated() < 2) {
1262+
return true;
1263+
}
1264+
12601265
// no output shape validation for now
12611266
$task->setOutput($output);
12621267
$taskEntity = \OC\TaskProcessing\Db\Task::fromPublicTask($task);

lib/public/TaskProcessing/ISynchronousOptionsProvider.php renamed to lib/public/TaskProcessing/ISynchronousOptionsAwareProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* implement a task processing provider
1818
* @since 35.0.0
1919
*/
20-
interface ISynchronousOptionsProvider extends ISynchronousProvider {
20+
interface ISynchronousOptionsAwareProvider extends ISynchronousProvider {
2121

2222
/**
2323
* Returns the shape of optional output parameters

0 commit comments

Comments
 (0)