chore: add link to workflow (#13541)

This commit is contained in:
Yury Semikhatsky 2022-04-13 11:56:00 -07:00 committed by GitHub
parent 269716d7d7
commit 00199b5617
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 7 deletions

View file

@ -34,6 +34,9 @@ const githubFactory: GridFactory = {
capacity: 4, capacity: 4,
launchTimeout: 10 * 60_000, launchTimeout: 10 * 60_000,
retireTimeout: 1 * 60 * 60_000, retireTimeout: 1 * 60 * 60_000,
statusUrl: (runId: string) => {
return `https://github.com/${repoName}/actions/runs/${runId}`;
},
launch: async (options: GridAgentLaunchOptions) => { launch: async (options: GridAgentLaunchOptions) => {
await createWorkflow(options); await createWorkflow(options);
}, },

View file

@ -37,6 +37,7 @@ export type GridFactory = {
capacity?: number, capacity?: number,
launchTimeout?: number, launchTimeout?: number,
retireTimeout?: number, retireTimeout?: number,
statusUrl?: (runId: string) => string;
launch: (launchOptions: GridAgentLaunchOptions) => Promise<void>, launch: (launchOptions: GridAgentLaunchOptions) => Promise<void>,
}; };
@ -116,13 +117,14 @@ class GridWorker extends EventEmitter {
} }
} }
type AgentStatus = 'none' | 'created' | 'connected' | 'retiring'; type AgentStatus = 'none' | 'created' | 'connected' | 'idle';
class GridAgent extends EventEmitter { class GridAgent extends EventEmitter {
private _capacity: number; private _capacity: number;
readonly agentId = createGuid(); readonly agentId = createGuid();
readonly os: string; readonly os: string;
private _ws: WebSocket | undefined; private _ws: WebSocket | undefined;
runId: string | undefined;
readonly _workers = new Map<string, GridWorker>(); readonly _workers = new Map<string, GridWorker>();
private _status: AgentStatus = 'none'; private _status: AgentStatus = 'none';
private _workersWaitingForAgentConnected: Set<GridWorker> = new Set(); private _workersWaitingForAgentConnected: Set<GridWorker> = new Set();
@ -152,10 +154,11 @@ class GridAgent extends EventEmitter {
this._status = status; this._status = status;
} }
agentConnected(ws: WebSocket) { agentConnected(ws: WebSocket, runId?: string) {
clearTimeout(this._agentCreationTimeoutId); clearTimeout(this._agentCreationTimeoutId);
this.setStatus('connected'); this.setStatus('connected');
this._ws = ws; this._ws = ws;
this.runId = runId;
for (const worker of this._workersWaitingForAgentConnected) for (const worker of this._workersWaitingForAgentConnected)
this._sendStartWorkerMessage(worker); this._sendStartWorkerMessage(worker);
this._workersWaitingForAgentConnected.clear(); this._workersWaitingForAgentConnected.clear();
@ -177,7 +180,7 @@ class GridAgent extends EventEmitter {
this._workers.delete(worker.workerId); this._workers.delete(worker.workerId);
this._workersWaitingForAgentConnected.delete(worker); this._workersWaitingForAgentConnected.delete(worker);
if (!this._workers.size) { if (!this._workers.size) {
this.setStatus('retiring'); this.setStatus('idle');
if (this._retireTimeoutId) if (this._retireTimeoutId)
clearTimeout(this._retireTimeoutId); clearTimeout(this._retireTimeoutId);
if (this._retireTimeout && isFinite(this._retireTimeout)) if (this._retireTimeout && isFinite(this._retireTimeout))
@ -300,7 +303,8 @@ export class GridServer {
return; return;
} }
agent.agentConnected(ws); const runId = params.get('runId') || undefined;
agent.agentConnected(ws, runId);
return; return;
} }
@ -355,6 +359,11 @@ export class GridServer {
} }
private _state(): string { private _state(): string {
const linkifyStatus = (agent: GridAgent) => {
if (agent.runId && this._factory.statusUrl)
return `<a href="${this._factory.statusUrl(agent.runId)}">${agent.status()}</a>`;
return agent.status();
};
return ` return `
<section style="display: flex; flex-direction: row"> <section style="display: flex; flex-direction: row">
<div style="display: flex; flex-direction: column; align-items: end; margin-right: 1ex;"> <div style="display: flex; flex-direction: column; align-items: end; margin-right: 1ex;">
@ -372,15 +381,15 @@ export class GridServer {
<ul> <ul>
${[...this._agents].map(([agentId, agent]) => ` ${[...this._agents].map(([agentId, agent]) => `
<li> <li>
<div>Agent <code>${mangle(agentId)}</code>: ${agent.status()}</div> <div>Agent (${agent.os}) <code>${mangle(agentId)}</code>: ${linkifyStatus(agent)}</div>
<div>Workers: ${agent._workers.size}</div> <div>Workers: ${agent._workers.size}</div>
<ul> <ul>
${[...agent._workers].map(([workerId, worker]) => ` ${[...agent._workers].map(([workerId, worker]) => `
<li>worker <code>${mangle(workerId)}</code> - ${JSON.stringify(worker.debugInfo())}</li> <li>worker <code>${mangle(workerId)}</code> - ${JSON.stringify(worker.debugInfo())}</li>
`)} `).join('')}
</ul> </ul>
</li> </li>
`)} `).join('')}
</ul> </ul>
`; `;
} }