mirror of
https://github.com/nextcloud/server.git
synced 2026-06-13 18:50:47 -04:00
fix: Remove static vars in TaskProcessing, TextProcessing, TextToImage
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
c3db7fa0e8
commit
b44f6a2957
7 changed files with 36 additions and 33 deletions
|
|
@ -76,12 +76,12 @@ class Task extends Entity {
|
|||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public static array $columns = ['id', 'last_updated', 'type', 'input', 'output', 'status', 'user_id', 'app_id', 'custom_id', 'completion_expected_at', 'error_message', 'progress', 'webhook_uri', 'webhook_method', 'scheduled_at', 'started_at', 'ended_at', 'allow_cleanup', 'user_facing_error_message', 'include_watermark'];
|
||||
public const array COLUMNS = ['id', 'last_updated', 'type', 'input', 'output', 'status', 'user_id', 'app_id', 'custom_id', 'completion_expected_at', 'error_message', 'progress', 'webhook_uri', 'webhook_method', 'scheduled_at', 'started_at', 'ended_at', 'allow_cleanup', 'user_facing_error_message', 'include_watermark'];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public static array $fields = ['id', 'lastUpdated', 'type', 'input', 'output', 'status', 'userId', 'appId', 'customId', 'completionExpectedAt', 'errorMessage', 'progress', 'webhookUri', 'webhookMethod', 'scheduledAt', 'startedAt', 'endedAt', 'allowCleanup', 'userFacingErrorMessage', 'includeWatermark'];
|
||||
public const array FIELDS = ['id', 'lastUpdated', 'type', 'input', 'output', 'status', 'userId', 'appId', 'customId', 'completionExpectedAt', 'errorMessage', 'progress', 'webhookUri', 'webhookMethod', 'scheduledAt', 'startedAt', 'endedAt', 'allowCleanup', 'userFacingErrorMessage', 'includeWatermark'];
|
||||
|
||||
public function __construct() {
|
||||
// add types in constructor
|
||||
|
|
@ -108,9 +108,9 @@ class Task extends Entity {
|
|||
}
|
||||
|
||||
public function toRow(): array {
|
||||
return array_combine(self::$columns, array_map(function ($field) {
|
||||
return array_combine(self::COLUMNS, array_map(function ($field) {
|
||||
return $this->{'get' . ucfirst($field)}();
|
||||
}, self::$fields));
|
||||
}, self::FIELDS));
|
||||
}
|
||||
|
||||
public static function fromPublicTask(OCPTask $task): self {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class TaskMapper extends QBMapper {
|
|||
*/
|
||||
public function find(int $id): Task {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select(Task::$columns)
|
||||
$qb->select(Task::COLUMNS)
|
||||
->from($this->tableName)
|
||||
->where($qb->expr()->eq('id', $qb->createPositionalParameter($id)));
|
||||
return $this->findEntity($qb);
|
||||
|
|
@ -53,7 +53,7 @@ class TaskMapper extends QBMapper {
|
|||
*/
|
||||
public function findOldestScheduledByType(array $taskTypes, array $taskIdsToIgnore): Task {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select(Task::$columns)
|
||||
$qb->select(Task::COLUMNS)
|
||||
->from($this->tableName)
|
||||
->where($qb->expr()->eq('status', $qb->createPositionalParameter(\OCP\TaskProcessing\Task::STATUS_SCHEDULED, IQueryBuilder::PARAM_INT)))
|
||||
->setMaxResults(1)
|
||||
|
|
@ -85,7 +85,7 @@ class TaskMapper extends QBMapper {
|
|||
*/
|
||||
public function findByIdAndUser(int $id, ?string $userId): Task {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select(Task::$columns)
|
||||
$qb->select(Task::COLUMNS)
|
||||
->from($this->tableName)
|
||||
->where($qb->expr()->eq('id', $qb->createPositionalParameter($id)));
|
||||
if ($userId === null) {
|
||||
|
|
@ -105,7 +105,7 @@ class TaskMapper extends QBMapper {
|
|||
*/
|
||||
public function findByUserAndTaskType(?string $userId, ?string $taskType = null, ?string $customId = null): array {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select(Task::$columns)
|
||||
$qb->select(Task::COLUMNS)
|
||||
->from($this->tableName)
|
||||
->where($qb->expr()->eq('user_id', $qb->createPositionalParameter($userId)));
|
||||
if ($taskType !== null) {
|
||||
|
|
@ -126,7 +126,7 @@ class TaskMapper extends QBMapper {
|
|||
*/
|
||||
public function findUserTasksByApp(?string $userId, string $appId, ?string $customId = null): array {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select(Task::$columns)
|
||||
$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)));
|
||||
|
|
@ -151,7 +151,7 @@ class TaskMapper extends QBMapper {
|
|||
?string $userId, ?string $taskType = null, ?string $appId = null, ?string $customId = null,
|
||||
?int $status = null, ?int $scheduleAfter = null, ?int $endedBefore = null): array {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select(Task::$columns)
|
||||
$qb->select(Task::COLUMNS)
|
||||
->from($this->tableName);
|
||||
|
||||
// empty string: no userId filter
|
||||
|
|
@ -205,7 +205,7 @@ class TaskMapper extends QBMapper {
|
|||
*/
|
||||
public function getTasksToCleanup(int $timeout, bool $force = false): \Generator {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select(Task::$columns)
|
||||
$qb->select(Task::COLUMNS)
|
||||
->from($this->tableName)
|
||||
->where($qb->expr()->lt('last_updated', $qb->createPositionalParameter($this->timeFactory->getDateTime()->getTimestamp() - $timeout)));
|
||||
if (!$force) {
|
||||
|
|
@ -244,7 +244,7 @@ class TaskMapper extends QBMapper {
|
|||
*/
|
||||
public function findNOldestScheduledByType(array $taskTypes, array $taskIdsToIgnore, int $numberOfTasks) {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select(Task::$columns)
|
||||
$qb->select(Task::COLUMNS)
|
||||
->from($this->tableName)
|
||||
->where($qb->expr()->eq('status', $qb->createPositionalParameter(\OCP\TaskProcessing\Task::STATUS_SCHEDULED, IQueryBuilder::PARAM_INT)))
|
||||
->setMaxResults($numberOfTasks)
|
||||
|
|
|
|||
|
|
@ -46,12 +46,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'];
|
||||
public const array COLUMNS = ['id', 'last_updated', 'type', 'input', 'output', 'status', 'user_id', 'app_id', 'identifier', 'completion_expected_at'];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public static array $fields = ['id', 'lastUpdated', 'type', 'input', 'output', 'status', 'userId', 'appId', 'identifier', 'completionExpectedAt'];
|
||||
public const array FIELDS = ['id', 'lastUpdated', 'type', 'input', 'output', 'status', 'userId', 'appId', 'identifier', 'completionExpectedAt'];
|
||||
|
||||
public function __construct() {
|
||||
// add types in constructor
|
||||
|
|
@ -68,9 +68,9 @@ class Task extends Entity {
|
|||
}
|
||||
|
||||
public function toRow(): array {
|
||||
return array_combine(self::$columns, array_map(function ($field) {
|
||||
return array_combine(self::COLUMNS, array_map(function ($field) {
|
||||
return $this->{'get' . ucfirst($field)}();
|
||||
}, self::$fields));
|
||||
}, self::FIELDS));
|
||||
}
|
||||
|
||||
public static function fromPublicTask(OCPTask $task): Task {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class TaskMapper extends QBMapper {
|
|||
*/
|
||||
public function find(int $id): Task {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select(Task::$columns)
|
||||
$qb->select(Task::COLUMNS)
|
||||
->from($this->tableName)
|
||||
->where($qb->expr()->eq('id', $qb->createPositionalParameter($id)));
|
||||
return $this->findEntity($qb);
|
||||
|
|
@ -53,7 +53,7 @@ class TaskMapper extends QBMapper {
|
|||
*/
|
||||
public function findByIdAndUser(int $id, ?string $userId): Task {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select(Task::$columns)
|
||||
$qb->select(Task::COLUMNS)
|
||||
->from($this->tableName)
|
||||
->where($qb->expr()->eq('id', $qb->createPositionalParameter($id)));
|
||||
if ($userId === null) {
|
||||
|
|
@ -73,7 +73,7 @@ class TaskMapper extends QBMapper {
|
|||
*/
|
||||
public function findUserTasksByApp(string $userId, string $appId, ?string $identifier = null): array {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select(Task::$columns)
|
||||
$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)));
|
||||
|
|
|
|||
|
|
@ -44,7 +44,10 @@ class Manager implements IManager {
|
|||
/** @var ?IProvider[] */
|
||||
private ?array $providers = null;
|
||||
|
||||
private static array $taskProcessingCompatibleTaskTypes = [
|
||||
/**
|
||||
* @var array<class-string, string>
|
||||
*/
|
||||
private const array COMPATIBLE_TASK_TYPES = [
|
||||
FreePromptTaskType::class => TextToText::ID,
|
||||
HeadlineTaskType::class => TextToTextHeadline::ID,
|
||||
SummaryTaskType::class => TextToTextSummary::ID,
|
||||
|
|
@ -93,7 +96,7 @@ class Manager implements IManager {
|
|||
public function hasProviders(): bool {
|
||||
// check if task processing equivalent types are available
|
||||
$taskTaskTypes = $this->taskProcessingManager->getAvailableTaskTypes();
|
||||
foreach (self::$taskProcessingCompatibleTaskTypes as $textTaskTypeClass => $taskTaskTypeId) {
|
||||
foreach (self::COMPATIBLE_TASK_TYPES as $textTaskTypeClass => $taskTaskTypeId) {
|
||||
if (isset($taskTaskTypes[$taskTaskTypeId])) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -118,7 +121,7 @@ class Manager implements IManager {
|
|||
|
||||
// check if task processing equivalent types are available
|
||||
$taskTaskTypes = $this->taskProcessingManager->getAvailableTaskTypes();
|
||||
foreach (self::$taskProcessingCompatibleTaskTypes as $textTaskTypeClass => $taskTaskTypeId) {
|
||||
foreach (self::COMPATIBLE_TASK_TYPES as $textTaskTypeClass => $taskTaskTypeId) {
|
||||
if (isset($taskTaskTypes[$taskTaskTypeId])) {
|
||||
$tasks[$textTaskTypeClass] = true;
|
||||
}
|
||||
|
|
@ -138,9 +141,9 @@ class Manager implements IManager {
|
|||
public function runTask(OCPTask $task): string {
|
||||
// try to run a task processing task if possible
|
||||
$taskTypeClass = $task->getType();
|
||||
if (isset(self::$taskProcessingCompatibleTaskTypes[$taskTypeClass]) && isset($this->taskProcessingManager->getAvailableTaskTypes()[self::$taskProcessingCompatibleTaskTypes[$taskTypeClass]])) {
|
||||
if (isset(self::COMPATIBLE_TASK_TYPES[$taskTypeClass]) && isset($this->taskProcessingManager->getAvailableTaskTypes()[self::COMPATIBLE_TASK_TYPES[$taskTypeClass]])) {
|
||||
try {
|
||||
$taskProcessingTaskTypeId = self::$taskProcessingCompatibleTaskTypes[$taskTypeClass];
|
||||
$taskProcessingTaskTypeId = self::COMPATIBLE_TASK_TYPES[$taskTypeClass];
|
||||
$taskProcessingTask = new \OCP\TaskProcessing\Task(
|
||||
$taskProcessingTaskTypeId,
|
||||
['input' => $task->getInput()],
|
||||
|
|
@ -227,8 +230,8 @@ class Manager implements IManager {
|
|||
$task->setStatus(OCPTask::STATUS_SCHEDULED);
|
||||
$providers = $this->getPreferredProviders($task);
|
||||
$equivalentTaskProcessingTypeAvailable = (
|
||||
isset(self::$taskProcessingCompatibleTaskTypes[$task->getType()])
|
||||
&& isset($this->taskProcessingManager->getAvailableTaskTypes()[self::$taskProcessingCompatibleTaskTypes[$task->getType()]])
|
||||
isset(self::COMPATIBLE_TASK_TYPES[$task->getType()])
|
||||
&& isset($this->taskProcessingManager->getAvailableTaskTypes()[self::COMPATIBLE_TASK_TYPES[$task->getType()]])
|
||||
);
|
||||
if (count($providers) === 0 && !$equivalentTaskProcessingTypeAvailable) {
|
||||
throw new PreConditionNotMetException('No LanguageModel provider is installed that can handle this task');
|
||||
|
|
|
|||
|
|
@ -49,12 +49,12 @@ class Task extends Entity {
|
|||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public static array $columns = ['id', 'last_updated', 'input', 'status', 'user_id', 'app_id', 'identifier', 'number_of_images', 'completion_expected_at'];
|
||||
public const array COLUMNS = ['id', 'last_updated', 'input', 'status', 'user_id', 'app_id', 'identifier', 'number_of_images', 'completion_expected_at'];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public static array $fields = ['id', 'lastUpdated', 'input', 'status', 'userId', 'appId', 'identifier', 'numberOfImages', 'completionExpectedAt'];
|
||||
public const array FIELDS = ['id', 'lastUpdated', 'input', 'status', 'userId', 'appId', 'identifier', 'numberOfImages', 'completionExpectedAt'];
|
||||
|
||||
public function __construct() {
|
||||
// add types in constructor
|
||||
|
|
@ -70,9 +70,9 @@ class Task extends Entity {
|
|||
}
|
||||
|
||||
public function toRow(): array {
|
||||
return array_combine(self::$columns, array_map(function ($field) {
|
||||
return array_combine(self::COLUMNS, array_map(function ($field) {
|
||||
return $this->{'get' . ucfirst($field)}();
|
||||
}, self::$fields));
|
||||
}, self::FIELDS));
|
||||
}
|
||||
|
||||
public static function fromPublicTask(OCPTask $task): Task {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class TaskMapper extends QBMapper {
|
|||
*/
|
||||
public function find(int $id): Task {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select(Task::$columns)
|
||||
$qb->select(Task::COLUMNS)
|
||||
->from($this->tableName)
|
||||
->where($qb->expr()->eq('id', $qb->createPositionalParameter($id)));
|
||||
return $this->findEntity($qb);
|
||||
|
|
@ -54,7 +54,7 @@ class TaskMapper extends QBMapper {
|
|||
*/
|
||||
public function findByIdAndUser(int $id, ?string $userId): Task {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select(Task::$columns)
|
||||
$qb->select(Task::COLUMNS)
|
||||
->from($this->tableName)
|
||||
->where($qb->expr()->eq('id', $qb->createPositionalParameter($id)));
|
||||
if ($userId === null) {
|
||||
|
|
@ -74,7 +74,7 @@ class TaskMapper extends QBMapper {
|
|||
*/
|
||||
public function findUserTasksByApp(?string $userId, string $appId, ?string $identifier = null): array {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select(Task::$columns)
|
||||
$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)));
|
||||
|
|
|
|||
Loading…
Reference in a new issue