Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions ci/phpunit/inc/utils/TaskUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public function testEditNotes(): void {
* @throws Exception
*/
public function testGetStatus(): void {
$this->assertEquals(3, TaskUtils::getStatus([], 100, 100));
$this->assertEquals(3, TaskUtils::getStatus([], 100, 101));
$taskObjects = $this->createTaskHelper();
$this->assertEquals(2, TaskUtils::getStatus($taskObjects["task"]));

//TODO test status 1 (running) and 2 (idle) too
//TODO test status 1 (running) and 3 (completed) too
}

/**
Expand Down
9 changes: 1 addition & 8 deletions src/inc/apiv2/model/TaskAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,7 @@ protected function getAggregateSearched(object $object): string {

protected function getAggregateStatus(object $object): int {
/** @var Task $object */
$keyspace = $object->getKeyspace();
$keyspaceProgress = $object->getKeyspaceProgress();

// the filter for progress is needed so we reduce the checked chunks numbers by a lot
$qF1 = new QueryFilter(Chunk::TASK_ID, $object->getId(), "=");
$qF2 = new QueryFilter(Chunk::PROGRESS, 10000, "<");
$chunks = Factory::getChunkFactory()->filter([Factory::FILTER => [$qF1, $qF2]]);
return TaskUtils::getStatus($chunks, $keyspace, $keyspaceProgress);
return TaskUtils::getStatus($object);
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/inc/apiv2/model/TaskWrapperDisplayAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,7 @@ protected function getAggregateStatus(object $object): int {
$total = 0;
$status = 0;
foreach ($tasks as $task) {
$qF1 = new QueryFilter(Chunk::TASK_ID, $task->getId(), "=");
$qF2 = new QueryFilter(Chunk::PROGRESS, 10000, "<");
$chunks = Factory::getChunkFactory()->filter([Factory::FILTER => [$qF1, $qF2]]);
$taskStatus = TaskUtils::getStatus($chunks, $task->getKeyspace(), $task->getKeyspaceProgress());
$taskStatus = TaskUtils::getStatus($task);
// if one task of the wrapper is running, it is running
if ($taskStatus === 1) {
$status = 1;
Expand Down
13 changes: 10 additions & 3 deletions src/inc/utils/TaskUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,25 @@ public static function editNotes($taskId, $notes, $user) {

// Function for taskwrapper api to determine based on the chunks if a task is running, idle or completed.
// Status 1 is running, 2 is idle and 3 is completed.
public static function getStatus($chunks, $keyspace, $keyspaceProgress) {
/**
* @param Task $task
*/
public static function getStatus($task) {
$qF1 = new QueryFilter(Chunk::TASK_ID, $task->getId(), "=");
$qF2 = new QueryFilter(Chunk::PROGRESS, 10000, "<");
$chunks = Factory::getChunkFactory()->filter([Factory::FILTER => [$qF1, $qF2]]);
//status 1 is running, 2 is idle and 3 is completed.
$status = 2;
if ($keyspaceProgress >= $keyspace && $keyspaceProgress > 0) {
$keyspaceProgress = TaskUtils::getTaskProgress($task);
if ($keyspaceProgress >= $task->getKeyspace() && $keyspaceProgress > 0) {
$status = 3;
}
else {
$now = time();
$chunkTimeOut = SConfig::getInstance()->getVal(DConfig::CHUNK_TIMEOUT);

foreach ($chunks as $chunk) {
if ($now - max($chunk->getSolveTime(), $chunk->getDispatchTime()) < $chunkTimeOut && $chunk->getProgress() < 10000) {
if ($now - max($chunk->getSolveTime(), $chunk->getDispatchTime()) < $chunkTimeOut) {
$status = 1;
Comment thread
jessevz marked this conversation as resolved.
break;
}
Expand Down
Loading