feat: implement input event system with durable command handling
- Introduced InputEvent model with status tracking (PENDING, PROCESSING, SUCCEEDED, FAILED) and unique request IDs. - Added DatabaseTurnDaemonTransport for sending commands and handling idempotency. - Implemented executeInputEvent function to manage input event lifecycle and error handling. - Created DatabaseTurnDaemonCommandQueue for managing command processing and lease recovery. - Enhanced turn daemon lifecycle to support atomic command execution and error recovery. - Added tests for input event atomicity, command queuing, and error handling scenarios.
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import type { TurnDaemonTransport } from './transport.js';
|
||||
import type { TurnDaemonCommand, TurnDaemonCommandResult, TurnDaemonStatus } from './types.js';
|
||||
|
||||
export class IdempotentTurnDaemonTransport implements TurnDaemonTransport {
|
||||
private sequence = 0;
|
||||
|
||||
constructor(
|
||||
private readonly transport: TurnDaemonTransport,
|
||||
private readonly parentRequestId: string
|
||||
) {}
|
||||
|
||||
async sendCommand(command: TurnDaemonCommand): Promise<string> {
|
||||
return this.transport.sendCommand(this.scope(command));
|
||||
}
|
||||
|
||||
async requestCommand(command: TurnDaemonCommand, timeoutMs?: number): Promise<TurnDaemonCommandResult | null> {
|
||||
return this.transport.requestCommand(this.scope(command), timeoutMs);
|
||||
}
|
||||
|
||||
async requestStatus(timeoutMs?: number): Promise<TurnDaemonStatus | null> {
|
||||
return this.transport.requestStatus(timeoutMs);
|
||||
}
|
||||
|
||||
private scope(command: TurnDaemonCommand): TurnDaemonCommand {
|
||||
const requestId = `${this.parentRequestId}:engine:${this.sequence++}:${command.type}`;
|
||||
return { ...command, requestId } as TurnDaemonCommand;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user