fix(ops): dynamic git branch/commit parsing and task status update to done in Control Tower poller
This commit is contained in:
parent
65b006cb9a
commit
daa2fada00
|
|
@ -14,7 +14,7 @@ class ControlTowerPollCommand extends Command
|
||||||
{--token=pending-205 : Token di autenticazione}
|
{--token=pending-205 : Token di autenticazione}
|
||||||
{--dry-run : Esegue in modalita simulazione senza invocare agy o pubblicare report}';
|
{--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
|
public function handle(): int
|
||||||
{
|
{
|
||||||
|
|
@ -40,6 +40,9 @@ public function handle(): int
|
||||||
$this->line("📋 Task ID: <comment>{$taskId}</comment>");
|
$this->line("📋 Task ID: <comment>{$taskId}</comment>");
|
||||||
$this->line("📝 Titolo: <comment>{$title}</comment>");
|
$this->line("📝 Titolo: <comment>{$title}</comment>");
|
||||||
|
|
||||||
|
$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) {
|
if ($dryRun) {
|
||||||
$this->info('🧪 DRY RUN ATTIVO: simulazione completata senza chiamare agy ne inviare report.');
|
$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)',
|
'ESITO_205' => 'riuscito (DRY RUN)',
|
||||||
'TASK_ID' => $taskId,
|
'TASK_ID' => $taskId,
|
||||||
'REPOSITORY' => 'ssh://git@git.netgescon.it:2222/michele/netgescon-day0.git',
|
'REPOSITORY' => 'ssh://git@git.netgescon.it:2222/michele/netgescon-day0.git',
|
||||||
'BRANCH' => 'stabilization/205-zero',
|
'BRANCH' => $currentBranch,
|
||||||
'COMMIT' => trim(shell_exec('git rev-parse HEAD') ?: '103d39e76589b0aad716596b5a1abe52ad1ea32a'),
|
'COMMIT' => $currentCommit,
|
||||||
'TEST_ESEGUITI' => 'bash -n wrapper, python3 -m py_compile parser, php artisan netgescon:control-tower-poll --dry-run',
|
'TEST_ESEGUITI' => 'bash -n wrapper, python3 -m py_compile parser, php artisan netgescon:control-tower-poll --dry-run',
|
||||||
'BLOCCO_DATI' => 'no',
|
'BLOCCO_DATI' => 'no',
|
||||||
'NOTE' => 'Poller testato con successo in modalita dry-run.'
|
'NOTE' => 'Poller testato con successo in modalita dry-run.'
|
||||||
|
|
@ -102,12 +105,15 @@ public function handle(): int
|
||||||
$parsed = $this->parseRunnerOutput($rawOutput);
|
$parsed = $this->parseRunnerOutput($rawOutput);
|
||||||
|
|
||||||
// 5. Post report to Control Tower
|
// 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->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;
|
return self::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -177,16 +183,21 @@ private function parseRunnerOutput(string $rawOutput): array
|
||||||
return ['raw_text' => $rawOutput];
|
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 {
|
try {
|
||||||
$commit = trim(shell_exec('git rev-parse HEAD') ?: '103d39e76589b0aad716596b5a1abe52ad1ea32a');
|
|
||||||
|
|
||||||
$reportText = implode("\n", [
|
$reportText = implode("\n", [
|
||||||
"ESITO_205: " . ($parsed['esito_205'] ?? 'riuscito'),
|
"ESITO_205: " . ($parsed['esito_205'] ?? 'riuscito'),
|
||||||
"TASK_ID: {$taskId}",
|
"TASK_ID: {$taskId}",
|
||||||
"REPOSITORY: ssh://git@git.netgescon.it:2222/michele/netgescon-day0.git",
|
"REPOSITORY: ssh://git@git.netgescon.it:2222/michele/netgescon-day0.git",
|
||||||
"BRANCH: stabilization/205-zero",
|
"BRANCH: {$branch}",
|
||||||
"COMMIT: {$commit}",
|
"COMMIT: {$commit}",
|
||||||
"TEST_ESEGUITI: " . ($parsed['test_eseguiti'] ?? 'Control Tower Poller test'),
|
"TEST_ESEGUITI: " . ($parsed['test_eseguiti'] ?? 'Control Tower Poller test'),
|
||||||
"BLOCCO_DATI: " . ($parsed['blocco_dati'] ?? 'no'),
|
"BLOCCO_DATI: " . ($parsed['blocco_dati'] ?? 'no'),
|
||||||
|
|
@ -200,13 +211,37 @@ private function publishReport(string $towerBase, string $machineId, string $tas
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($response->successful()) {
|
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 {
|
} else {
|
||||||
$this->warn("Risposta non 20x dall'API report: " . $response->status());
|
$this->warn("Risposta non 20x dall'API report: " . $response->status());
|
||||||
}
|
}
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
$this->error("Errore invio report: {$e->getMessage()}");
|
$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
|
private function sendHeartbeat(string $towerBase, string $machineId, string $token, string $taskId): void
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user