mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-12-04 22:21:21 +09:00
Add the deploy_log/deploy_status handlers and subscribeDeploy/unsubscribeDeploy to the socket singleton, and useDeployJobStream — one hook for the console, the compact widget, the LogsTab banner and the topbar pill. It boots from a full snapshot, prefers the live socket channel, de-dupes log rows by DB id, re-syncs with after_id on every (re)connect, and falls back to 2s polling when sockets are unavailable (plan 51 D2/§5.5). DeploymentJobProgress now consumes the hook and links to the full console. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
97 lines
3.7 KiB
React
97 lines
3.7 KiB
React
import { useEffect, useRef } from 'react';
|
|
import { Link } from 'react-router-dom';
|
|
import useDeployJobStream from '../hooks/useDeployJobStream';
|
|
|
|
// Shared "watch it come up live" compact panel: streams a DeploymentJob (socket
|
|
// with an after_id poll fallback, via useDeployJobStream) and renders its
|
|
// status, progress bar, current step and a log tail. Used by the Templates
|
|
// install modal and the service Logs tab so every deploy flow behaves the same.
|
|
// The full-page Deploy Console (/deployments/:jobId) is the richer view; this
|
|
// widget links to it via "Open console →".
|
|
//
|
|
// Terminal handling (unchanged contract):
|
|
// - status 'succeeded' -> onSuccess(job)
|
|
// - status 'failed' -> onFailure(job.error_message)
|
|
// - timeoutMs elapsed -> onFailure('timed out' message)
|
|
export default function DeploymentJobProgress({
|
|
jobId,
|
|
onSuccess,
|
|
onFailure,
|
|
timeoutMs = 600000,
|
|
showConsoleLink = true,
|
|
}) {
|
|
const { job, lines, error } = useDeployJobStream(jobId);
|
|
|
|
// Keep callbacks in refs so a re-rendering parent doesn't re-fire them.
|
|
const onSuccessRef = useRef(onSuccess);
|
|
const onFailureRef = useRef(onFailure);
|
|
onSuccessRef.current = onSuccess;
|
|
onFailureRef.current = onFailure;
|
|
const firedRef = useRef(false);
|
|
|
|
// Fire the terminal callback exactly once.
|
|
useEffect(() => {
|
|
if (!job || firedRef.current) return;
|
|
if (job.status === 'succeeded') {
|
|
firedRef.current = true;
|
|
onSuccessRef.current?.(job);
|
|
} else if (job.status === 'failed') {
|
|
firedRef.current = true;
|
|
onFailureRef.current?.(job.error_message || 'Deployment failed');
|
|
}
|
|
}, [job]);
|
|
|
|
// Hard timeout guard, mirroring the old widget so a job that never reaches a
|
|
// terminal state doesn't spin forever.
|
|
useEffect(() => {
|
|
if (!jobId) return undefined;
|
|
const t = setTimeout(() => {
|
|
if (firedRef.current) return;
|
|
firedRef.current = true;
|
|
const minutes = Math.round(timeoutMs / 60000);
|
|
onFailureRef.current?.(
|
|
`Deployment timed out after ${minutes} minutes without reaching a final state`
|
|
);
|
|
}, timeoutMs);
|
|
return () => clearTimeout(t);
|
|
}, [jobId, timeoutMs]);
|
|
|
|
const status = job?.status || 'pending';
|
|
const progress = job?.progress_percent ?? 0;
|
|
|
|
return (
|
|
<div className="deployment-job-progress">
|
|
<div className="deployment-progress">
|
|
<div className="deployment-progress-track">
|
|
<div
|
|
className="deployment-progress-fill"
|
|
style={{ width: `${progress}%` }}
|
|
/>
|
|
</div>
|
|
<span>{status} {progress}%</span>
|
|
</div>
|
|
{job?.current_step_name && (
|
|
<p className="deployment-job-progress__step text-muted">
|
|
Current step: {job.current_step_name}
|
|
</p>
|
|
)}
|
|
{error && (
|
|
<div className="alert alert-warning">
|
|
Trouble reaching the deployment job: {error}. Retrying…
|
|
</div>
|
|
)}
|
|
<pre className="log-viewer">
|
|
{lines.map(log => {
|
|
const prefix = log.step_index ? `[${log.step_index}] ` : '';
|
|
return `${prefix}${log.message}`;
|
|
}).join('\n') || 'Waiting for deployment logs...'}
|
|
</pre>
|
|
{showConsoleLink && jobId && (
|
|
<Link to={`/deployments/${jobId}`} className="deployment-job-progress__console-link">
|
|
Open console →
|
|
</Link>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|