aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMarcel Klehr <mklehr@gmx.net>2024-05-07 12:46:21 +0200
committerMarcel Klehr <mklehr@gmx.net>2024-05-14 11:38:41 +0200
commit4a3b9b826ea532991f8636b621f92760c321e93e (patch)
tree46c57ff0648993a2025ca7d25d0c491fc66f92b5 /lib
parentfff2fb8e77c7a58aa9323c13daa355d6d8f3a118 (diff)
downloadnextcloud-server-4a3b9b826ea532991f8636b621f92760c321e93e.tar.gz
nextcloud-server-4a3b9b826ea532991f8636b621f92760c321e93e.zip
refactor: identifier is now customId/custom_id
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Log/PsrLoggerAdapter.php37
-rw-r--r--lib/private/TaskProcessing/Db/Task.php12
-rw-r--r--lib/private/TaskProcessing/Db/TaskMapper.php8
-rw-r--r--lib/private/TaskProcessing/Manager.php4
-rw-r--r--lib/private/TaskProcessing/SynchronousBackgroundJob.php2
-rw-r--r--lib/public/TaskProcessing/IManager.php4
-rw-r--r--lib/public/TaskProcessing/ISynchronousProvider.php3
-rw-r--r--lib/public/TaskProcessing/Task.php12
8 files changed, 41 insertions, 41 deletions
diff --git a/lib/private/Log/PsrLoggerAdapter.php b/lib/private/Log/PsrLoggerAdapter.php
index 8b397ef8905..b126cb52d77 100644
--- a/lib/private/Log/PsrLoggerAdapter.php
+++ b/lib/private/Log/PsrLoggerAdapter.php
@@ -31,7 +31,6 @@ use OCP\ILogger;
use OCP\Log\IDataLogger;
use Psr\Log\InvalidArgumentException;
use Psr\Log\LoggerInterface;
-use Stringable;
use Throwable;
use function array_key_exists;
use function array_merge;
@@ -53,10 +52,10 @@ final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
/**
* System is unusable.
*
- * @param string|Stringable $message
+ * @param $message
* @param mixed[] $context
*/
- public function emergency(string|Stringable $message, array $context = []): void {
+ public function emergency($message, array $context = []): void {
if ($this->containsThrowable($context)) {
$this->logger->logException($context['exception'], array_merge(
[
@@ -76,10 +75,10 @@ final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
* Example: Entire website down, database unavailable, etc. This should
* trigger the SMS alerts and wake you up.
*
- * @param string|Stringable $message
+ * @param $message
* @param mixed[] $context
*/
- public function alert(string|Stringable $message, array $context = []): void {
+ public function alert($message, array $context = []): void {
if ($this->containsThrowable($context)) {
$this->logger->logException($context['exception'], array_merge(
[
@@ -98,10 +97,10 @@ final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
*
* Example: Application component unavailable, unexpected exception.
*
- * @param string|Stringable $message
+ * @param $message
* @param mixed[] $context
*/
- public function critical(string|Stringable $message, array $context = []): void {
+ public function critical($message, array $context = []): void {
if ($this->containsThrowable($context)) {
$this->logger->logException($context['exception'], array_merge(
[
@@ -119,10 +118,10 @@ final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
* Runtime errors that do not require immediate action but should typically
* be logged and monitored.
*
- * @param string|Stringable $message
+ * @param $message
* @param mixed[] $context
*/
- public function error(string|Stringable $message, array $context = []): void {
+ public function error($message, array $context = []): void {
if ($this->containsThrowable($context)) {
$this->logger->logException($context['exception'], array_merge(
[
@@ -142,10 +141,10 @@ final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
* Example: Use of deprecated APIs, poor use of an API, undesirable things
* that are not necessarily wrong.
*
- * @param string|Stringable $message
+ * @param $message
* @param mixed[] $context
*/
- public function warning(string|Stringable $message, array $context = []): void {
+ public function warning($message, array $context = []): void {
if ($this->containsThrowable($context)) {
$this->logger->logException($context['exception'], array_merge(
[
@@ -162,10 +161,10 @@ final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
/**
* Normal but significant events.
*
- * @param string|Stringable $message
+ * @param $message
* @param mixed[] $context
*/
- public function notice(string|Stringable $message, array $context = []): void {
+ public function notice($message, array $context = []): void {
if ($this->containsThrowable($context)) {
$this->logger->logException($context['exception'], array_merge(
[
@@ -184,10 +183,10 @@ final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
*
* Example: User logs in, SQL logs.
*
- * @param string|Stringable $message
+ * @param $message
* @param mixed[] $context
*/
- public function info(string|Stringable $message, array $context = []): void {
+ public function info($message, array $context = []): void {
if ($this->containsThrowable($context)) {
$this->logger->logException($context['exception'], array_merge(
[
@@ -204,10 +203,10 @@ final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
/**
* Detailed debug information.
*
- * @param string|Stringable $message
+ * @param $message
* @param mixed[] $context
*/
- public function debug(string|Stringable $message, array $context = []): void {
+ public function debug($message, array $context = []): void {
if ($this->containsThrowable($context)) {
$this->logger->logException($context['exception'], array_merge(
[
@@ -225,12 +224,12 @@ final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
* Logs with an arbitrary level.
*
* @param mixed $level
- * @param string|Stringable $message
+ * @param $message
* @param mixed[] $context
*
* @throws InvalidArgumentException
*/
- public function log($level, string|Stringable $message, array $context = []): void {
+ public function log($level, $message, array $context = []): void {
if (!is_int($level) || $level < ILogger::DEBUG || $level > ILogger::FATAL) {
throw new InvalidArgumentException('Nextcloud allows only integer log levels');
}
diff --git a/lib/private/TaskProcessing/Db/Task.php b/lib/private/TaskProcessing/Db/Task.php
index 6e181285c90..11892a14960 100644
--- a/lib/private/TaskProcessing/Db/Task.php
+++ b/lib/private/TaskProcessing/Db/Task.php
@@ -43,7 +43,7 @@ use OCP\TaskProcessing\Task as OCPTask;
* @method string|null getUserId()
* @method setAppId(string $type)
* @method string getAppId()
- * @method setIdentifier(string $identifier)
+ * @method setIdentifier(string $customId)
* @method string getIdentifier()
* @method setCompletionExpectedAt(null|\DateTime $completionExpectedAt)
* @method null|\DateTime getCompletionExpectedAt()
@@ -60,7 +60,7 @@ class Task extends Entity {
protected $status;
protected $userId;
protected $appId;
- protected $identifier;
+ protected $customId;
protected $completionExpectedAt;
protected $errorMessage;
protected $progress;
@@ -68,12 +68,12 @@ class Task extends Entity {
/**
* @var string[]
*/
- public static array $columns = ['id', 'last_updated', 'type', 'input', 'output', 'status', 'user_id', 'app_id', 'identifier', 'completion_expected_at', 'error_message', 'progress'];
+ public static array $columns = ['id', 'last_updated', 'type', 'input', 'output', 'status', 'user_id', 'app_id', 'custom_id', 'completion_expected_at', 'error_message', 'progress'];
/**
* @var string[]
*/
- public static array $fields = ['id', 'lastUpdated', 'type', 'input', 'output', 'status', 'userId', 'appId', 'identifier', 'completionExpectedAt', 'errorMessage', 'progress'];
+ public static array $fields = ['id', 'lastUpdated', 'type', 'input', 'output', 'status', 'userId', 'appId', 'customId', 'completionExpectedAt', 'errorMessage', 'progress'];
public function __construct() {
@@ -86,7 +86,7 @@ class Task extends Entity {
$this->addType('status', 'integer');
$this->addType('userId', 'string');
$this->addType('appId', 'string');
- $this->addType('identifier', 'string');
+ $this->addType('customId', 'string');
$this->addType('completionExpectedAt', 'datetime');
$this->addType('errorMessage', 'string');
$this->addType('progress', 'float');
@@ -110,7 +110,7 @@ class Task extends Entity {
'errorMessage' => $task->getErrorMessage(),
'userId' => $task->getUserId(),
'appId' => $task->getAppId(),
- 'identifier' => $task->getIdentifier(),
+ 'customId' => $task->getIdentifier(),
'completionExpectedAt' => $task->getCompletionExpectedAt(),
'progress' => $task->getProgress(),
]);
diff --git a/lib/private/TaskProcessing/Db/TaskMapper.php b/lib/private/TaskProcessing/Db/TaskMapper.php
index 7ba16105f4c..bdb59e5180e 100644
--- a/lib/private/TaskProcessing/Db/TaskMapper.php
+++ b/lib/private/TaskProcessing/Db/TaskMapper.php
@@ -103,18 +103,18 @@ class TaskMapper extends QBMapper {
/**
* @param string $userId
* @param string $appId
- * @param string|null $identifier
+ * @param string|null $customId
* @return list<Task>
* @throws Exception
*/
- public function findUserTasksByApp(string $userId, string $appId, ?string $identifier = null): array {
+ public function findUserTasksByApp(string $userId, string $appId, ?string $customId = null): array {
$qb = $this->db->getQueryBuilder();
$qb->select(Task::$columns)
->from($this->tableName)
->where($qb->expr()->eq('user_id', $qb->createPositionalParameter($userId)))
->andWhere($qb->expr()->eq('app_id', $qb->createPositionalParameter($appId)));
- if ($identifier !== null) {
- $qb->andWhere($qb->expr()->eq('identifier', $qb->createPositionalParameter($identifier)));
+ if ($customId !== null) {
+ $qb->andWhere($qb->expr()->eq('custom_id', $qb->createPositionalParameter($customId)));
}
return array_values($this->findEntities($qb));
}
diff --git a/lib/private/TaskProcessing/Manager.php b/lib/private/TaskProcessing/Manager.php
index 2770fd277ab..86587a94c23 100644
--- a/lib/private/TaskProcessing/Manager.php
+++ b/lib/private/TaskProcessing/Manager.php
@@ -797,9 +797,9 @@ class Manager implements IManager {
}
}
- public function getUserTasksByApp(?string $userId, string $appId, ?string $identifier = null): array {
+ public function getUserTasksByApp(?string $userId, string $appId, ?string $customId = null): array {
try {
- $taskEntities = $this->taskMapper->findUserTasksByApp($userId, $appId, $identifier);
+ $taskEntities = $this->taskMapper->findUserTasksByApp($userId, $appId, $customId);
return array_map(fn ($taskEntity): Task => $taskEntity->toPublicTask(), $taskEntities);
} catch (\OCP\DB\Exception $e) {
throw new \OCP\TaskProcessing\Exception\Exception('There was a problem finding a task', 0, $e);
diff --git a/lib/private/TaskProcessing/SynchronousBackgroundJob.php b/lib/private/TaskProcessing/SynchronousBackgroundJob.php
index c7f4706c392..ba1844b1da1 100644
--- a/lib/private/TaskProcessing/SynchronousBackgroundJob.php
+++ b/lib/private/TaskProcessing/SynchronousBackgroundJob.php
@@ -57,7 +57,7 @@ class SynchronousBackgroundJob extends QueuedJob {
return;
}
try {
- $output = $provider->process($task->getUserId(), $input);
+ $output = $provider->process($task->getUserId(), $input, fn(float $progress) => $this->taskProcessingManager->setTaskProgress($task->getId(), $progress));
} catch (ProcessingException $e) {
$this->logger->warning('Failed to process a TaskProcessing task with synchronous provider ' . $provider->getId(), ['exception' => $e]);
$this->taskProcessingManager->setTaskResult($task->getId(), $e->getMessage(), null);
diff --git a/lib/public/TaskProcessing/IManager.php b/lib/public/TaskProcessing/IManager.php
index 71c04d009ef..e1a5c16546c 100644
--- a/lib/public/TaskProcessing/IManager.php
+++ b/lib/public/TaskProcessing/IManager.php
@@ -138,13 +138,13 @@ interface IManager {
/**
* @param string|null $userId
* @param string $appId
- * @param string|null $identifier
+ * @param string|null $customId
* @return list<Task>
* @throws Exception If the query failed
* @throws \JsonException If parsing the task input and output failed
* @since 30.0.0
*/
- public function getUserTasksByApp(?string $userId, string $appId, ?string $identifier = null): array;
+ public function getUserTasksByApp(?string $userId, string $appId, ?string $customId = null): array;
/**
* Prepare the task's input data, so it can be processed by the provider
diff --git a/lib/public/TaskProcessing/ISynchronousProvider.php b/lib/public/TaskProcessing/ISynchronousProvider.php
index 16d66414b64..a58ce6faf1b 100644
--- a/lib/public/TaskProcessing/ISynchronousProvider.php
+++ b/lib/public/TaskProcessing/ISynchronousProvider.php
@@ -41,9 +41,10 @@ interface ISynchronousProvider extends IProvider {
*
* @param null|string $userId The user that created the current task
* @param array<string, list<numeric|string|File>|numeric|string|File> $input The task input
+ * @param callable(float):bool $reportProgress Report the task progress. If this returns false, that means the task was cancelled and processing should be stopped.
* @psalm-return array<string, list<numeric|string>|numeric|string>
* @throws ProcessingException
*@since 30.0.0
*/
- public function process(?string $userId, array $input): array;
+ public function process(?string $userId, array $input, callable $reportProgress): array;
}
diff --git a/lib/public/TaskProcessing/Task.php b/lib/public/TaskProcessing/Task.php
index 3645970e4b3..b6aa6376279 100644
--- a/lib/public/TaskProcessing/Task.php
+++ b/lib/public/TaskProcessing/Task.php
@@ -79,7 +79,7 @@ final class Task implements \JsonSerializable {
* @param array<string,list<numeric|string>|numeric|string> $input
* @param string $appId
* @param string|null $userId
- * @param null|string $identifier An arbitrary identifier for this task. max length: 255 chars
+ * @param null|string $customId An arbitrary customId for this task. max length: 255 chars
* @since 30.0.0
*/
final public function __construct(
@@ -87,7 +87,7 @@ final class Task implements \JsonSerializable {
protected array $input,
protected readonly string $appId,
protected readonly ?string $userId,
- protected readonly ?string $identifier = '',
+ protected readonly ?string $customId = '',
) {
}
@@ -182,8 +182,8 @@ final class Task implements \JsonSerializable {
* @return null|string
* @since 30.0.0
*/
- final public function getIdentifier(): ?string {
- return $this->identifier;
+ final public function getCustomId(): ?string {
+ return $this->customId;
}
/**
@@ -195,7 +195,7 @@ final class Task implements \JsonSerializable {
}
/**
- * @psalm-return array{id: ?int, type: string, status: 'STATUS_CANCELLED'|'STATUS_FAILED'|'STATUS_SUCCESSFUL'|'STATUS_RUNNING'|'STATUS_SCHEDULED'|'STATUS_UNKNOWN', userId: ?string, appId: string, input: array<array-key, list<numeric|string>|numeric|string>, output: ?array<array-key, list<numeric|string>|numeric|string>, identifier: ?string, completionExpectedAt: ?int, progress: ?float}
+ * @psalm-return array{id: ?int, type: string, status: 'STATUS_CANCELLED'|'STATUS_FAILED'|'STATUS_SUCCESSFUL'|'STATUS_RUNNING'|'STATUS_SCHEDULED'|'STATUS_UNKNOWN', userId: ?string, appId: string, input: array<array-key, list<numeric|string>|numeric|string>, output: ?array<array-key, list<numeric|string>|numeric|string>, customId: ?string, completionExpectedAt: ?int, progress: ?float}
* @since 30.0.0
*/
final public function jsonSerialize(): array {
@@ -207,7 +207,7 @@ final class Task implements \JsonSerializable {
'appId' => $this->getAppId(),
'input' => $this->getInput(),
'output' => $this->getOutput(),
- 'identifier' => $this->getIdentifier(),
+ 'customId' => $this->getCustomId(),
'completionExpectedAt' => $this->getCompletionExpectedAt()?->getTimestamp(),
'progress' => $this->getProgress(),
];