From 00199b561787cd36a00bac4b310d148117c4d620 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Wed, 13 Apr 2022 11:56:00 -0700 Subject: [PATCH] chore: add link to workflow (#13541) --- .../src/grid/githubGridFactory.ts | 3 +++ .../playwright-core/src/grid/gridServer.ts | 23 +++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/packages/playwright-core/src/grid/githubGridFactory.ts b/packages/playwright-core/src/grid/githubGridFactory.ts index 2e3445c28a..21ea3bb81b 100644 --- a/packages/playwright-core/src/grid/githubGridFactory.ts +++ b/packages/playwright-core/src/grid/githubGridFactory.ts @@ -34,6 +34,9 @@ const githubFactory: GridFactory = { capacity: 4, launchTimeout: 10 * 60_000, retireTimeout: 1 * 60 * 60_000, + statusUrl: (runId: string) => { + return `https://github.com/${repoName}/actions/runs/${runId}`; + }, launch: async (options: GridAgentLaunchOptions) => { await createWorkflow(options); }, diff --git a/packages/playwright-core/src/grid/gridServer.ts b/packages/playwright-core/src/grid/gridServer.ts index d895d656c8..5757923962 100644 --- a/packages/playwright-core/src/grid/gridServer.ts +++ b/packages/playwright-core/src/grid/gridServer.ts @@ -37,6 +37,7 @@ export type GridFactory = { capacity?: number, launchTimeout?: number, retireTimeout?: number, + statusUrl?: (runId: string) => string; launch: (launchOptions: GridAgentLaunchOptions) => Promise, }; @@ -116,13 +117,14 @@ class GridWorker extends EventEmitter { } } -type AgentStatus = 'none' | 'created' | 'connected' | 'retiring'; +type AgentStatus = 'none' | 'created' | 'connected' | 'idle'; class GridAgent extends EventEmitter { private _capacity: number; readonly agentId = createGuid(); readonly os: string; private _ws: WebSocket | undefined; + runId: string | undefined; readonly _workers = new Map(); private _status: AgentStatus = 'none'; private _workersWaitingForAgentConnected: Set = new Set(); @@ -152,10 +154,11 @@ class GridAgent extends EventEmitter { this._status = status; } - agentConnected(ws: WebSocket) { + agentConnected(ws: WebSocket, runId?: string) { clearTimeout(this._agentCreationTimeoutId); this.setStatus('connected'); this._ws = ws; + this.runId = runId; for (const worker of this._workersWaitingForAgentConnected) this._sendStartWorkerMessage(worker); this._workersWaitingForAgentConnected.clear(); @@ -177,7 +180,7 @@ class GridAgent extends EventEmitter { this._workers.delete(worker.workerId); this._workersWaitingForAgentConnected.delete(worker); if (!this._workers.size) { - this.setStatus('retiring'); + this.setStatus('idle'); if (this._retireTimeoutId) clearTimeout(this._retireTimeoutId); if (this._retireTimeout && isFinite(this._retireTimeout)) @@ -300,7 +303,8 @@ export class GridServer { return; } - agent.agentConnected(ws); + const runId = params.get('runId') || undefined; + agent.agentConnected(ws, runId); return; } @@ -355,6 +359,11 @@ export class GridServer { } private _state(): string { + const linkifyStatus = (agent: GridAgent) => { + if (agent.runId && this._factory.statusUrl) + return `${agent.status()}`; + return agent.status(); + }; return `
@@ -372,15 +381,15 @@ export class GridServer {
    ${[...this._agents].map(([agentId, agent]) => `
  • -
    Agent ${mangle(agentId)}: ${agent.status()}
    +
    Agent (${agent.os}) ${mangle(agentId)}: ${linkifyStatus(agent)}
    Workers: ${agent._workers.size}
      ${[...agent._workers].map(([workerId, worker]) => `
    • worker ${mangle(workerId)} - ${JSON.stringify(worker.debugInfo())}
    • - `)} + `).join('')}
  • - `)} + `).join('')}
`; }