diff --git a/src/inc/apiv2/model/TaskAPI.php b/src/inc/apiv2/model/TaskAPI.php index 7753ea0b2..2d2ca6162 100644 --- a/src/inc/apiv2/model/TaskAPI.php +++ b/src/inc/apiv2/model/TaskAPI.php @@ -178,13 +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; } - $keyspace = $object->getKeyspace(); $keyspaceProgress = $object->getKeyspaceProgress(); @@ -195,34 +194,34 @@ 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; } 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($chunks)){ + $chunks = Factory::getChunkFactory()->filter([Factory::FILTER => $qF]); + } $currentSpeed = 0; $cProgress = 0;