Private
Public Access
1
0

fix: add job-level WS events so jobs show completed status
Some checks failed
CI Pipeline / Rust Format Check (push) Failing after 24s
CI Pipeline / Clippy Lints (push) Successful in 1m4s
CI Pipeline / Rust Unit Tests (push) Successful in 1m21s
CI Pipeline / Security Audit (push) Successful in 5s
CI Pipeline / Frontend Lint & Type Check (push) Successful in 16s
CI Pipeline / Build .deb & Release (push) Has been skipped

- Frontend: handleWsEvent now distinguishes host vs job events
  - Host events only update detail rows + optimistic counters
  - Job events (event_type=job) set authoritative status + counts
- Backend ws_relay: NotifyPayload now includes event_type field
  - Host events: event_type=host
  - update_parent_job_status fires pg_notify with event_type=job
- Backend job_executor: sync_job_status fires pg_notify with event_type=job
- Backend jobs cancel endpoint fires pg_notify with event_type=job
- Fixes jobs appearing stuck because host status was mapped to job status
This commit is contained in:
2026-05-03 16:34:38 +00:00
parent 1c03522835
commit 9627febe90
5 changed files with 176 additions and 36 deletions

View File

@ -17,6 +17,7 @@ use std::sync::Arc;
use chrono::{Duration as ChronoDuration, Utc};
use pm_agent_client::{types::ApplyPatchesRequest, AgentClient};
use pm_core::config::AppConfig;
use serde_json::json;
use sqlx::{FromRow, PgPool};
use tokio::{sync::Semaphore, time};
use uuid::Uuid;
@ -840,6 +841,28 @@ async fn sync_job_status(pool: &PgPool, job_id: Uuid) {
tracing::error!(%job_id, error = %e, "sync_job_status: failed to update parent job");
}
// Fire job-level pg_notify so the frontend can update the job row.
let notify_payload = json!({
"event_type": "job",
"job_id": job_id.to_string(),
"host_id": "",
"status": new_status,
"succeeded_count": counts.succeeded_count,
"failed_count": counts.failed_count,
"host_count": counts.total_count,
});
if let Ok(payload_str) = serde_json::to_string(&notify_payload) {
if let Err(e) = sqlx::query("SELECT pg_notify('job_update', $1)")
.bind(&payload_str)
.execute(pool)
.await
{
tracing::error!(%job_id, error = %e, "sync_job_status: job-level pg_notify failed");
} else {
tracing::info!(%job_id, status = %new_status, "sync_job_status: job-level pg_notify sent");
}
}
// Send email notifications for completed/failed jobs
if set_completed {
// Spawn email notification in background — non-blocking