From ca5232f322781c4ed19772a5751c914794f68f4b Mon Sep 17 00:00:00 2001 From: jessevz Date: Wed, 18 Mar 2026 14:19:23 +0100 Subject: [PATCH 1/5] Added a flag isActive to tasks api response to show wether a task is active --- src/inc/apiv2/model/TaskAPI.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/inc/apiv2/model/TaskAPI.php b/src/inc/apiv2/model/TaskAPI.php index 7753ea0b2..c24dcaf50 100644 --- a/src/inc/apiv2/model/TaskAPI.php +++ b/src/inc/apiv2/model/TaskAPI.php @@ -184,6 +184,20 @@ function aggregateData(object $object, array &$included_data = [], ?array $aggre $activeAgents = Factory::getAssignmentFactory()->countFilter([Factory::FILTER => $qF]); $aggregatedData["activeAgents"] = $activeAgents; } + + $chunks = null; + if (is_null($aggregateFieldsets) || in_array("isActive", $aggregateFieldsets['task'])) { + $qF = new QueryFilter(Chunk::TASK_ID, $object->getId(), "="); + $chunks = Factory::getChunkFactory()->filter([Factory::FILTER => $qF]); + $isActive = 0; + foreach ($chunks as $chunk) { + if (time() - max($chunk->getSolveTime(), $chunk->getDispatchTime()) < SConfig::getInstance()->getVal(DConfig::CHUNK_TIMEOUT) && $chunk->getProgress() < 10000) { + $isActive = 1; + break; + } + } + $aggregatedData["isActive"] = $isActive; + } $keyspace = $object->getKeyspace(); $keyspaceProgress = $object->getKeyspaceProgress(); @@ -222,7 +236,9 @@ function aggregateData(object $object, array &$included_data = [], ?array $aggre if (is_null($aggregateFieldsets) || in_array("taskExtraDetails", $aggregateFieldsets['task'])) { $qF = new QueryFilter(Chunk::TASK_ID, $object->getId(), "="); - $chunks = Factory::getChunkFactory()->filter([Factory::FILTER => $qF]); + if (!isset($chunk)){ + $chunks = Factory::getChunkFactory()->filter([Factory::FILTER => $qF]); + } $currentSpeed = 0; $cProgress = 0; From d1c388d703c59b3adf077b31773cbead4ba7c45e Mon Sep 17 00:00:00 2001 From: jessevz Date: Wed, 18 Mar 2026 14:22:24 +0100 Subject: [PATCH 2/5] changed flag to boolean --- src/inc/apiv2/model/TaskAPI.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/inc/apiv2/model/TaskAPI.php b/src/inc/apiv2/model/TaskAPI.php index c24dcaf50..08a7c81ee 100644 --- a/src/inc/apiv2/model/TaskAPI.php +++ b/src/inc/apiv2/model/TaskAPI.php @@ -189,10 +189,10 @@ function aggregateData(object $object, array &$included_data = [], ?array $aggre if (is_null($aggregateFieldsets) || in_array("isActive", $aggregateFieldsets['task'])) { $qF = new QueryFilter(Chunk::TASK_ID, $object->getId(), "="); $chunks = Factory::getChunkFactory()->filter([Factory::FILTER => $qF]); - $isActive = 0; + $isActive = false; foreach ($chunks as $chunk) { if (time() - max($chunk->getSolveTime(), $chunk->getDispatchTime()) < SConfig::getInstance()->getVal(DConfig::CHUNK_TIMEOUT) && $chunk->getProgress() < 10000) { - $isActive = 1; + $isActive = true; break; } } From 98c599fc7aac3aa79433ac399605f66211fbac3d Mon Sep 17 00:00:00 2001 From: jessevz Date: Wed, 18 Mar 2026 14:47:35 +0100 Subject: [PATCH 3/5] Fixed wrong used variable --- src/inc/apiv2/model/TaskAPI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inc/apiv2/model/TaskAPI.php b/src/inc/apiv2/model/TaskAPI.php index 08a7c81ee..de630dd44 100644 --- a/src/inc/apiv2/model/TaskAPI.php +++ b/src/inc/apiv2/model/TaskAPI.php @@ -236,7 +236,7 @@ function aggregateData(object $object, array &$included_data = [], ?array $aggre if (is_null($aggregateFieldsets) || in_array("taskExtraDetails", $aggregateFieldsets['task'])) { $qF = new QueryFilter(Chunk::TASK_ID, $object->getId(), "="); - if (!isset($chunk)){ + if (!isset($chunks)){ $chunks = Factory::getChunkFactory()->filter([Factory::FILTER => $qF]); } From 10436714c6aa9d2b6cc00ad6a69564cc6fad252d Mon Sep 17 00:00:00 2001 From: jessevz Date: Wed, 18 Mar 2026 14:50:42 +0100 Subject: [PATCH 4/5] Moved unnesesary logic outside loop --- src/inc/apiv2/model/TaskAPI.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/inc/apiv2/model/TaskAPI.php b/src/inc/apiv2/model/TaskAPI.php index de630dd44..e2926c697 100644 --- a/src/inc/apiv2/model/TaskAPI.php +++ b/src/inc/apiv2/model/TaskAPI.php @@ -190,8 +190,11 @@ function aggregateData(object $object, array &$included_data = [], ?array $aggre $qF = new QueryFilter(Chunk::TASK_ID, $object->getId(), "="); $chunks = Factory::getChunkFactory()->filter([Factory::FILTER => $qF]); $isActive = false; + $now = time(); + $chunkTimeOut = SConfig::getInstance()->getVal(DConfig::CHUNK_TIMEOUT); + foreach ($chunks as $chunk) { - if (time() - max($chunk->getSolveTime(), $chunk->getDispatchTime()) < SConfig::getInstance()->getVal(DConfig::CHUNK_TIMEOUT) && $chunk->getProgress() < 10000) { + if ($now - max($chunk->getSolveTime(), $chunk->getDispatchTime()) < $chunkTimeOut && $chunk->getProgress() < 10000) { $isActive = true; break; } From 438c174574768113b79b2a3ec4144dd203da1adb Mon Sep 17 00:00:00 2001 From: jessevz Date: Wed, 18 Mar 2026 16:29:50 +0100 Subject: [PATCH 5/5] Use the original status variable for the task status --- src/inc/apiv2/model/TaskAPI.php | 60 +++++++++++---------------------- 1 file changed, 20 insertions(+), 40 deletions(-) diff --git a/src/inc/apiv2/model/TaskAPI.php b/src/inc/apiv2/model/TaskAPI.php index e2926c697..2d2ca6162 100644 --- a/src/inc/apiv2/model/TaskAPI.php +++ b/src/inc/apiv2/model/TaskAPI.php @@ -178,30 +178,12 @@ function aggregateData(object $object, array &$included_data = [], ?array $aggre $aggregateFieldsets['task'] = explode(",", $aggregateFieldsets['task']); } - $activeAgents = []; - if (is_null($aggregateFieldsets) || in_array("activeAgents", $aggregateFieldsets['task'])) { + $assignedAgents = []; + if (is_null($aggregateFieldsets) || in_array("assignedAgents", $aggregateFieldsets['task'])) { $qF = new QueryFilter(Assignment::TASK_ID, $object->getId(), "="); - $activeAgents = Factory::getAssignmentFactory()->countFilter([Factory::FILTER => $qF]); - $aggregatedData["activeAgents"] = $activeAgents; + $assignedAgents = Factory::getAssignmentFactory()->countFilter([Factory::FILTER => $qF]); + $aggregatedData["totalAssignedAgents"] = $assignedAgents; } - - $chunks = null; - if (is_null($aggregateFieldsets) || in_array("isActive", $aggregateFieldsets['task'])) { - $qF = new QueryFilter(Chunk::TASK_ID, $object->getId(), "="); - $chunks = Factory::getChunkFactory()->filter([Factory::FILTER => $qF]); - $isActive = false; - $now = time(); - $chunkTimeOut = SConfig::getInstance()->getVal(DConfig::CHUNK_TIMEOUT); - - foreach ($chunks as $chunk) { - if ($now - max($chunk->getSolveTime(), $chunk->getDispatchTime()) < $chunkTimeOut && $chunk->getProgress() < 10000) { - $isActive = true; - break; - } - } - $aggregatedData["isActive"] = $isActive; - } - $keyspace = $object->getKeyspace(); $keyspaceProgress = $object->getKeyspaceProgress(); @@ -212,28 +194,26 @@ function aggregateData(object $object, array &$included_data = [], ?array $aggre if (is_null($aggregateFieldsets) || in_array("searched", $aggregateFieldsets['task'])) { $aggregatedData["searched"] = Util::showperc(TaskUtils::getTaskProgress($object), $keyspace); } - - if (is_null($aggregateFieldsets) || in_array("status", $aggregateFieldsets['task'])) { - $qF1 = new QueryFilter(Chunk::TASK_ID, $object->getId(), "="); - $agg1 = new Aggregation(Chunk::CHECKPOINT, Aggregation::SUM); - $agg2 = new Aggregation(Chunk::SKIP, Aggregation::SUM); - $agg3 = new Aggregation(Chunk::DISPATCH_TIME, Aggregation::MAX); - $agg4 = new Aggregation(Chunk::SOLVE_TIME, Aggregation::MAX); - $results = Factory::getChunkFactory()->multicolAggregationFilter([Factory::FILTER => $qF1], [$agg1, $agg2, $agg3, $agg4]); - - $progress = $results[$agg1->getName()] - $results[$agg2->getName()]; - $maxTime = max($results[$agg3->getName()], $results[$agg4->getName()]); - - //status 1 is running, 2 is idle and 3 is completed + + $chunks = null; + if (is_null($aggregateFieldsets) || in_array("isActive", $aggregateFieldsets['task'])) { + $qF = new QueryFilter(Chunk::TASK_ID, $object->getId(), "="); + $chunks = Factory::getChunkFactory()->filter([Factory::FILTER => $qF]); + //status 1 is running, 2 is idle and 3 is completed. $status = 2; - if (time() - $maxTime < SConfig::getInstance()->getVal(DConfig::CHUNK_TIMEOUT) && ($progress < $keyspace || $object->getUsePreprocessor() && $keyspace == DPrince::PRINCE_KEYSPACE)) { - $status = 1; - } - if ($keyspaceProgress >= $keyspace && $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) { + $status = 1; + break; + } + } } - $aggregatedData["status"] = $status; }