MCPcopy Create free account
hub / github.com/tiann/hapi / updateRunnerState

Method updateRunnerState

cli/src/api/apiMachine.ts:343–374  ·  view source on GitHub ↗
(handler: (state: RunnerState | null) => RunnerState)

Source from the content-addressed store, hash-verified

341 }
342
343 async updateRunnerState(handler: (state: RunnerState | null) => RunnerState): Promise<void> {
344 await backoff(async () => {
345 const updated = handler(this.machine.runnerState)
346
347 const answer = await this.socket.emitWithAck('machine-update-state', {
348 machineId: this.machine.id,
349 runnerState: updated,
350 expectedVersion: this.machine.runnerStateVersion
351 }) as unknown
352
353 applyVersionedAck(answer, {
354 valueKey: 'runnerState',
355 parseValue: (value) => {
356 const parsed = RunnerStateSchema.safeParse(value)
357 return parsed.success ? parsed.data : null
358 },
359 applyValue: (value) => {
360 this.machine.runnerState = value
361 },
362 applyVersion: (version) => {
363 this.machine.runnerStateVersion = version
364 },
365 logInvalidValue: (context, version) => {
366 const suffix = context === 'success' ? 'ack' : 'version-mismatch ack'
367 logger.debug(`[API MACHINE] Ignoring invalid runnerState value from ${suffix}`, { version })
368 },
369 invalidResponseMessage: 'Invalid machine-update-state response',
370 errorMessage: 'Machine state update failed',
371 versionMismatchMessage: 'Runner state version mismatch'
372 })
373 })
374 }
375
376 connect(): void {
377 this.socket = io(`${configuration.apiUrl}/cli`, {

Callers 3

connectMethod · 0.95
startRunnerFunction · 0.80
cleanupAndShutdownFunction · 0.80

Calls 3

applyVersionedAckFunction · 0.90
handlerFunction · 0.85
debugMethod · 0.80

Tested by

no test coverage detected