Add operation flows and activity logs for betas and campaigns
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
export interface ActivityEvent { id: number; created_at: string; message: string }
|
||||
export interface OperationStep { label: string; state: 'pending' | 'current' | 'done' | 'failed' }
|
||||
|
||||
interface BetaServer {
|
||||
stage: string; deployed_at: string | null; restarted_at: string | null;
|
||||
healthy_at: string | null; match_seen_at: string | null;
|
||||
}
|
||||
|
||||
export function betaFlow(beta: { state: string; wait_for_health: number; wait_for_match: number }, servers: BetaServer[]): OperationStep[] {
|
||||
const stages = ['deploying', 'awaiting-empty', 'restarting'];
|
||||
const labels = ['Deploy artifacts', 'Wait for empty servers', 'Restart servers'];
|
||||
if (beta.wait_for_health) { stages.push('awaiting-health'); labels.push('Verify health'); }
|
||||
if (beta.wait_for_match) { stages.push('awaiting-match'); labels.push('Observe a completed match'); }
|
||||
stages.push('ready'); labels.push('Review and promote');
|
||||
const positions = servers.map(s => {
|
||||
if (s.stage !== 'failed') return Math.max(0, stages.indexOf(s.stage));
|
||||
if (!s.deployed_at) return 0;
|
||||
if (!s.restarted_at) return 2;
|
||||
if (beta.wait_for_health && !s.healthy_at) return stages.indexOf('awaiting-health');
|
||||
if (beta.wait_for_match && !s.match_seen_at) return stages.indexOf('awaiting-match');
|
||||
return stages.length - 1;
|
||||
});
|
||||
const current = beta.state === 'promoted' ? stages.length
|
||||
: beta.state === 'ready-promote' ? stages.length - 1
|
||||
: positions.length ? Math.min(...positions) : 0;
|
||||
return labels.map((label, i) => ({ label, state: i < current ? 'done' : i === current
|
||||
? beta.state === 'rolled-back' ? 'pending' : servers.some((s, j) => s.stage === 'failed' && positions[j] === i) ? 'failed' : 'current'
|
||||
: 'pending' }));
|
||||
}
|
||||
|
||||
export function campaignFlow(servers: { restart_state: string; restarted_at: string | null; files_changed: number }[], finished: boolean): OperationStep[] {
|
||||
const positions = servers.map(s => s.restart_state === 'done' ? 4
|
||||
: s.restart_state === 'failed' && !s.files_changed ? 0
|
||||
: s.restarted_at ? 3 : 1);
|
||||
const current = positions.length ? Math.min(...positions) : finished ? 4 : 0;
|
||||
return ['Apply file changes', 'Wait for empty servers', 'Restart servers', 'Verify health'].map((label, i) => ({
|
||||
label, state: i < current ? 'done' : i !== current ? 'pending'
|
||||
: servers.some((s, j) => s.restart_state === 'failed' && positions[j] === i) ? 'failed'
|
||||
: servers.some(s => ['manual', 'held'].includes(s.restart_state)) ? 'pending' : 'current'
|
||||
}));
|
||||
}
|
||||
Reference in New Issue
Block a user