Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: archive tasks using bulk update with predefined batch #4104

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions actions/class.TaskQueueWebApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,48 @@ public function archive()
$this->checkIfTaskIdExists();
$taskIds = $this->detectTaskIds();

// Get task log service
$taskLogService = $this->getTaskLogService();

$filter = $taskIds === static::ALL
? (new TaskLogFilter())->availableForArchived($this->getSessionUserUri())
: (new TaskLogFilter())
// Define batch size for the chunk of tasks to be processed in each iteration
$batchSize = 1000; // Adjust this number based on server capabilities
$success = false;

// If taskIds is ALL, we'll fetch all tasks using pagination
if ($taskIds === static::ALL) {
do {
// Set the filter with limit and offset for pagination
$filter = (new TaskLogFilter())
->availableForArchived($this->getSessionUserUri())
->setLimit($batchSize)
->setSortBy(TaskLogBrokerInterface::COLUMN_CREATED_AT);
// Fetch the tasks for the current batch
$taskLogCollection = $taskLogService->search($filter);

// If no tasks are returned, break the loop
if (count($taskLogCollection) === 0) {
break;
}

// Process the current batch
$success = $taskLogService->archiveCollection($taskLogCollection) || $success;
} while (count($taskLogCollection) === $batchSize);
} else {
// Handle specific task IDs (no need for pagination)
$filter = (new TaskLogFilter())
->addAvailableFilters($this->getSessionUserUri())
->in(TaskLogBrokerInterface::COLUMN_ID, $taskIds);

// Fetch all tasks based on provided task IDs
$taskLogCollection = $taskLogService->search($filter);

// Process the tasks without pagination
$success = $taskLogService->archiveCollection($taskLogCollection);
}

// Return JSON response
return $this->returnJson([
'success' => (bool) $taskLogService->archiveCollection($taskLogService->search($filter))
'success' => (bool) $success
]);
} catch (Exception $e) {
$this->setErrorJsonResponse(
Expand Down
Loading