UNPKG

@mbc-cqrs-serverless/core

Version:
58 lines (57 loc) 3.46 kB
import { ConfigService } from '@nestjs/config'; import { DataSyncCommandSfnEvent, StepFunctionStateInput } from '../command-events/data-sync.sfn.event'; import { S3Service } from '../data-store'; import { CommandModel, CommandModuleOptions, DetailKey } from '../interfaces'; import { SnsService } from '../queue'; import { StepFunctionService } from '../step-func/step-function.service'; import { CommandService } from './command.service'; import { DataService } from './data.service'; import { HistoryService } from './history.service'; export declare class CommandEventHandler { private readonly options; private readonly commandService; private readonly dataService; private readonly historyService; private readonly s3Service; private readonly snsService; private readonly config; private readonly sfnService; private readonly logger; private readonly alarmTopicArn; constructor(options: CommandModuleOptions, commandService: CommandService, dataService: DataService, historyService: HistoryService, s3Service: S3Service, snsService: SnsService, config: ConfigService, sfnService: StepFunctionService); execute(event: DataSyncCommandSfnEvent): Promise<StepFunctionStateInput | StepFunctionStateInput[]>; protected handleStepState(event: DataSyncCommandSfnEvent): Promise<StepFunctionStateInput | StepFunctionStateInput[]>; protected waitConfirmToken(event: DataSyncCommandSfnEvent): Promise<StepFunctionStateInput>; /** * Retry wrapper around commandService.getItem for the cross-execution * predecessor-status check in waitConfirmToken. Bounded and short — * smooths a single transient DDB failure; does not wait out an outage. */ protected getItemWithRetry(key: DetailKey, options: { consistentRead: boolean; }, maxAttempts: number, baseDelayMs: number): Promise<CommandModel>; /** * Bounded retry with exponential backoff (baseDelayMs * 2^(attempt - 1)), * rethrowing the last error once every attempt is exhausted. Shared by both * sides of the version handshake so the pull path (waitConfirmToken) and the * push path (checkNextToken) tolerate transient DynamoDB failures equally. */ protected withRetry<T>(fn: () => Promise<T>, maxAttempts: number, baseDelayMs: number): Promise<T>; protected checkVersion(event: DataSyncCommandSfnEvent): Promise<StepFunctionStateInput>; protected setTtlCommand(event: DataSyncCommandSfnEvent): Promise<StepFunctionStateInput>; protected historyCopy(event: DataSyncCommandSfnEvent): Promise<StepFunctionStateInput>; protected transformData(event: DataSyncCommandSfnEvent): Promise<StepFunctionStateInput[]>; protected syncData(event: DataSyncCommandSfnEvent): Promise<StepFunctionStateInput>; protected checkNextToken(event: DataSyncCommandSfnEvent): Promise<StepFunctionStateInput>; protected handleResumeExecutionError(event: DataSyncCommandSfnEvent, e: unknown, options: { benignNames: ReadonlySet<string>; logContext: string; alarmPayload: Record<string, unknown>; }): Promise<void>; /** * Best-effort alarm publish — SNS failure must not fail the SFN step * (e.g. after updateTaskToken already succeeded). */ protected publishAlarmSafely(event: DataSyncCommandSfnEvent, errorDetails: any): Promise<void>; protected publishAlarm(event: DataSyncCommandSfnEvent, errorDetails: any): Promise<void>; }