Skip to content

Commit 02e1610

Browse files
author
jessevz
committed
Fixed status calculation in backend
1 parent d19bd17 commit 02e1610

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/inc/apiv2/model/tasks.routes.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use DBA\Factory;
55

66
use DBA\Agent;
7+
use DBA\Aggregation;
78
use DBA\Assignment;
89
use DBA\Chunk;
910
use DBA\CrackerBinary;
@@ -162,32 +163,35 @@ protected function createObject(array $data): int {
162163

163164
//TODO make aggregate data queryable and not included by default
164165
static function aggregateData(object $object): array {
166+
$qF = new QueryFilter(Assignment::TASK_ID, $object->getId(), "=");
167+
$activeAgents = Factory::getAssignmentFactory()->countFilter([Factory::FILTER => $qF]);
168+
$aggregatedData["activeAgents"] = $activeAgents;
169+
165170
$keyspace = $object->getKeyspace();
166171
$keyspaceProgress = $object->getKeyspaceProgress();
167172

173+
$qF1 = new QueryFilter(Chunk::TASK_ID, $object->getId(), "=");
174+
$agg1 = new Aggregation(Chunk::CHECKPOINT, Aggregation::SUM);
175+
$agg2 = new Aggregation(Chunk::SKIP, Aggregation::SUM);
176+
$agg3 = new Aggregation(Chunk::DISPATCH_TIME, Aggregation::MAX);
177+
$agg4 = new Aggregation(Chunk::SOLVE_TIME, Aggregation::MAX);
178+
$results = Factory::getChunkFactory()->multicolAggregationFilter([Factory::FILTER => $qF1], [$agg1, $agg2, $agg3, $agg4]);
179+
180+
$progress = $results[$agg1->getName()] - $results[$agg2->getName()];
181+
$maxTime = max($results[$agg3->getName()], $results[$agg4->getName()]);
182+
183+
//status 1 is running, 2 is idle and 3 is completed
184+
$status = 2;
185+
if (time() - $maxTime < SConfig::getInstance()->getVal(DConfig::CHUNK_TIMEOUT) && ($progress < $object->getKeyspace() || $object->getUsePreprocessor() && $object->getKeyspace() == DPrince::PRINCE_KEYSPACE)) {
186+
$status = 1;
187+
}
168188
$aggregatedData["dispatched"] = Util::showperc($keyspaceProgress, $keyspace);
169189
$aggregatedData["searched"] = Util::showperc(TaskUtils::getTaskProgress($object), $keyspace);
170190

171-
$qF = new QueryFilter(Chunk::TASK_ID, $object->getId(), "=");
172-
$chunks = Factory::getChunkFactory()->filter([Factory::FILTER => $qF]);
173-
174-
$activeAgents = [];
175-
foreach ($chunks as $chunk) {
176-
if (time() - max($chunk->getSolveTime(), $chunk->getDispatchTime()) < SConfig::getInstance()->getVal(DConfig::CHUNK_TIMEOUT) && $chunk->getProgress() < 10000) {
177-
$activeAgents[$chunk->getAgentId()] = true;
178-
}
179-
}
180-
181-
//status 1 is running, 2 is idle and 3 is completed
182-
$status = 2;
183191
if ($keyspaceProgress >= $keyspace && $keyspaceProgress > 0) {
184192
$status = 3;
185193
}
186-
elseif (count($activeAgents) > 0) {
187-
$status = 1;
188-
}
189194

190-
$aggregatedData["activeAgents"] = array_keys($activeAgents);
191195
$aggregatedData["status"] = $status;
192196

193197
return $aggregatedData;

0 commit comments

Comments
 (0)