diff --git a/app/Console/Commands/ControlTowerPollCommand.php b/app/Console/Commands/ControlTowerPollCommand.php
index 559ce73..3601711 100644
--- a/app/Console/Commands/ControlTowerPollCommand.php
+++ b/app/Console/Commands/ControlTowerPollCommand.php
@@ -14,7 +14,7 @@ class ControlTowerPollCommand extends Command
{--token=pending-205 : Token di autenticazione}
{--dry-run : Esegue in modalita simulazione senza invocare agy o pubblicare report}';
- protected $description = 'Polls Control Tower for tasks, executes prompt via stdin | agy -p -, parses runner output and publishes reports.';
+ protected $description = 'Polls Control Tower for tasks, executes prompt via stdin | agy -p -, parses runner output, publishes reports, and marks tasks as done.';
public function handle(): int
{
@@ -40,6 +40,9 @@ public function handle(): int
$this->line("๐ Task ID: {$taskId}");
$this->line("๐ Titolo: {$title}");
+ $currentBranch = trim(shell_exec('git rev-parse --abbrev-ref HEAD 2>/dev/null') ?: 'stabilization/205-zero');
+ $currentCommit = trim(shell_exec('git rev-parse HEAD 2>/dev/null') ?: '');
+
if ($dryRun) {
$this->info('๐งช DRY RUN ATTIVO: simulazione completata senza chiamare agy ne inviare report.');
@@ -47,8 +50,8 @@ public function handle(): int
'ESITO_205' => 'riuscito (DRY RUN)',
'TASK_ID' => $taskId,
'REPOSITORY' => 'ssh://git@git.netgescon.it:2222/michele/netgescon-day0.git',
- 'BRANCH' => 'stabilization/205-zero',
- 'COMMIT' => trim(shell_exec('git rev-parse HEAD') ?: '103d39e76589b0aad716596b5a1abe52ad1ea32a'),
+ 'BRANCH' => $currentBranch,
+ 'COMMIT' => $currentCommit,
'TEST_ESEGUITI' => 'bash -n wrapper, python3 -m py_compile parser, php artisan netgescon:control-tower-poll --dry-run',
'BLOCCO_DATI' => 'no',
'NOTE' => 'Poller testato con successo in modalita dry-run.'
@@ -102,12 +105,15 @@ public function handle(): int
$parsed = $this->parseRunnerOutput($rawOutput);
// 5. Post report to Control Tower
- $this->publishReport($towerBase, $machineId, $taskId, $rawOutput, $parsed);
+ $reportId = $this->publishReport($towerBase, $machineId, $taskId, $rawOutput, $parsed, $currentBranch, $currentCommit);
- // 6. Send heartbeat update
+ // 6. Update task status in Control Tower to 'done'
+ $this->updateTaskStatus($towerBase, $machineId, $token, $taskId, 'done');
+
+ // 7. Send heartbeat update
$this->sendHeartbeat($towerBase, $machineId, $token, $taskId);
- $this->info('โ
Task completato e report inviato alla Torre di Controllo.');
+ $this->info("โ
Task {$taskId} completato, report {$reportId} inviato e stato aggiornato a 'done' in Torre di Controllo.");
return self::SUCCESS;
}
@@ -177,16 +183,21 @@ private function parseRunnerOutput(string $rawOutput): array
return ['raw_text' => $rawOutput];
}
- private function publishReport(string $towerBase, string $machineId, string $taskId, string $rawOutput, array $parsed): void
- {
+ private function publishReport(
+ string $towerBase,
+ string $machineId,
+ string $taskId,
+ string $rawOutput,
+ array $parsed,
+ string $branch,
+ string $commit
+ ): string {
try {
- $commit = trim(shell_exec('git rev-parse HEAD') ?: '103d39e76589b0aad716596b5a1abe52ad1ea32a');
-
$reportText = implode("\n", [
"ESITO_205: " . ($parsed['esito_205'] ?? 'riuscito'),
"TASK_ID: {$taskId}",
"REPOSITORY: ssh://git@git.netgescon.it:2222/michele/netgescon-day0.git",
- "BRANCH: stabilization/205-zero",
+ "BRANCH: {$branch}",
"COMMIT: {$commit}",
"TEST_ESEGUITI: " . ($parsed['test_eseguiti'] ?? 'Control Tower Poller test'),
"BLOCCO_DATI: " . ($parsed['blocco_dati'] ?? 'no'),
@@ -200,13 +211,37 @@ private function publishReport(string $towerBase, string $machineId, string $tas
]);
if ($response->successful()) {
- $this->info("โ๏ธ Report inviato alla Torre di Controllo (ID: " . ($response->json('id') ?? 'OK') . ")");
+ $reportId = (string) ($response->json('id') ?? 'N/A');
+ $this->info("โ๏ธ Report inviato alla Torre di Controllo (ID: {$reportId})");
+ return $reportId;
} else {
$this->warn("Risposta non 20x dall'API report: " . $response->status());
}
} catch (Throwable $e) {
$this->error("Errore invio report: {$e->getMessage()}");
}
+ return 'N/A';
+ }
+
+ private function updateTaskStatus(string $towerBase, string $machineId, string $token, string $taskId, string $status = 'done'): void
+ {
+ try {
+ $response = Http::timeout(10)->post("{$towerBase}/api/tasks/status", [
+ 'task_id' => $taskId,
+ 'status' => $status,
+ 'machine_id' => $machineId,
+ 'token' => $token,
+ 'progress_note' => "Task {$taskId} completato da netgescon:control-tower-poll",
+ ]);
+
+ if ($response->successful()) {
+ $this->info("โ๏ธ Stato task {$taskId} aggiornato a '{$status}' su Torre di Controllo.");
+ } else {
+ $this->warn("Risposta non 20x aggiornamento stato task: " . $response->status());
+ }
+ } catch (Throwable $e) {
+ $this->error("Errore aggiornamento stato task: {$e->getMessage()}");
+ }
}
private function sendHeartbeat(string $towerBase, string $machineId, string $token, string $taskId): void