feat: 명령어 요청 ID 처리 개선 및 상태 응답 기능 업데이트

This commit is contained in:
2026-01-04 16:18:52 +00:00
parent 2753b85a26
commit ef2ced5f5e
7 changed files with 138 additions and 166 deletions
@@ -228,10 +228,12 @@ export class TurnDaemonLifecycle {
this.stopping = true;
return;
case 'getStatus': {
await this.commandResponder?.publishStatus(
command.requestId,
this.getStatus()
);
if (command.requestId) {
await this.commandResponder?.publishStatus(
command.requestId,
this.getStatus()
);
}
return;
}
case 'run':
@@ -285,7 +287,7 @@ export class TurnDaemonLifecycle {
} as TurnDaemonCommandResult;
}
if (this.commandResponder) {
if (this.commandResponder && command.requestId) {
await this.commandResponder.publishCommandResult(
command.requestId,
result
+18 -74
View File
@@ -1,78 +1,22 @@
export type TurnDaemonState = 'idle' | 'running' | 'flushing' | 'paused' | 'stopping';
import type {
TurnCheckpoint,
TurnDaemonCommand,
TurnDaemonCommandResult,
TurnDaemonStatus,
TurnRunBudget,
TurnRunResult,
} from '@sammo-ts/common';
export type RunReason = 'schedule' | 'manual' | 'poke';
export interface TurnRunBudget {
budgetMs: number;
maxGenerals: number;
catchUpCap: number;
}
export interface TurnCheckpoint {
turnTime: string;
generalId?: number;
year: number;
month: number;
}
export interface TurnRunResult {
lastTurnTime: string;
processedGenerals: number;
processedTurns: number;
durationMs: number;
partial: boolean;
checkpoint?: TurnCheckpoint;
}
export interface TurnDaemonStatus {
state: TurnDaemonState;
running: boolean;
paused: boolean;
lastError?: string;
lastRunAt?: string;
lastDurationMs?: number;
lastTurnTime?: string;
nextTurnTime?: string;
pendingReason?: RunReason;
queueDepth: number;
checkpoint?: TurnCheckpoint;
}
export type TurnDaemonCommand =
| { type: 'run'; reason: RunReason; targetTime?: string; budget?: TurnRunBudget }
| { type: 'pause'; reason?: string }
| { type: 'resume'; reason?: string }
| { type: 'shutdown'; reason?: string }
| { type: 'getStatus'; requestId: string }
| { type: 'troopJoin'; requestId: string; generalId: number; troopId: number }
| { type: 'troopExit'; requestId: string; generalId: number };
export type TurnDaemonCommandResult =
| {
type: 'troopJoin';
ok: true;
generalId: number;
troopId: number;
}
| {
type: 'troopJoin';
ok: false;
generalId: number;
troopId: number;
reason: string;
}
| {
type: 'troopExit';
ok: true;
generalId: number;
wasLeader: boolean;
}
| {
type: 'troopExit';
ok: false;
generalId: number;
reason: string;
};
export type {
RunReason,
TurnCheckpoint,
TurnDaemonCommand,
TurnDaemonCommandResult,
TurnDaemonState,
TurnDaemonStatus,
TurnRunBudget,
TurnRunResult,
} from '@sammo-ts/common';
export interface TurnDaemonCommandHandler {
handle(command: TurnDaemonCommand): Promise<TurnDaemonCommandResult | null>;