Backend: - migrations/003_jobs_scheduling.sql: retry_next_at/last_error columns, pg_notify trigger for immediate job dispatch, retry index - pm-agent-client: ApplyPatchesRequest/Response, AgentJobStatus, RollbackResponse types; apply_patches/job_status/rollback_job client methods + generic POST helper - pm-core/models: JobStatus, JobKind, PatchJob, PatchJobHost, CreateJobRequest, PatchJobSummary - pm-web/routes/jobs.rs: POST/GET /api/v1/jobs, GET /jobs/:id, POST /jobs/:id/cancel, POST /jobs/:id/rollback - pm-worker/job_executor.rs: NOTIFY listener, periodic scanner, execute_host_job, poll_running_jobs, handle_host_failure (3-retry exponential backoff 1m/5m/30m), sync_job_status, retry_pending_jobs - pm-worker/main.rs: spawn job_executor Frontend: - types/index.ts: PatchInfo, PatchJobHost, PatchJob, PatchJobSummary, CreateJobRequest interfaces - api/client.ts: jobsApi (list/get/create/cancel/rollback), patchesApi (getHostPatches) - pages/PatchDeploymentPage.tsx: 3-step MUI Stepper (host select → configure → result) - pages/JobsPage.tsx: job list table, expandable per-host detail, cancel/rollback actions with confirm dialog, load-more pagination - App.tsx: /jobs and /deployment routes wired to real pages cargo check: 0 errors | vite build: 0 errors
45 lines
1.4 KiB
PL/PgSQL
45 lines
1.4 KiB
PL/PgSQL
-- Migration: 003_jobs_scheduling
|
|
-- Description: Retry/scheduling columns for patch_job_hosts, and NOTIFY trigger
|
|
-- for immediate patch job dispatch.
|
|
|
|
-- ============================================================
|
|
-- Add retry-scheduling columns to patch_job_hosts
|
|
-- ============================================================
|
|
|
|
-- When the retry engine should next attempt this host; NULL = not scheduled
|
|
ALTER TABLE patch_job_hosts
|
|
ADD COLUMN retry_next_at TIMESTAMPTZ;
|
|
|
|
-- Last failure reason captured by the worker for display in the UI
|
|
ALTER TABLE patch_job_hosts
|
|
ADD COLUMN last_error TEXT;
|
|
|
|
-- ============================================================
|
|
-- pg_notify trigger: fires when an immediate job is inserted
|
|
-- ============================================================
|
|
|
|
CREATE OR REPLACE FUNCTION notify_job_enqueued()
|
|
RETURNS TRIGGER
|
|
LANGUAGE plpgsql
|
|
AS $$
|
|
BEGIN
|
|
IF NEW.immediate = TRUE THEN
|
|
PERFORM pg_notify('job_enqueued', NEW.id::text);
|
|
END IF;
|
|
RETURN NEW;
|
|
END;
|
|
$$;
|
|
|
|
CREATE TRIGGER trg_job_enqueued
|
|
AFTER INSERT ON patch_jobs
|
|
FOR EACH ROW
|
|
EXECUTE FUNCTION notify_job_enqueued();
|
|
|
|
-- ============================================================
|
|
-- Index: efficiently find hosts due for retry
|
|
-- ============================================================
|
|
|
|
CREATE INDEX idx_pjh_retry
|
|
ON patch_job_hosts (retry_next_at)
|
|
WHERE retry_next_at IS NOT NULL;
|