UNPKG

@bitblit/ratchet-epsilon-common

Version:

Tiny adapter to simplify building API gateway Lambda APIS

38 lines 1.51 kB
import { BackgroundExecutionEventType } from './background-execution-event-type.js'; import { ContextUtil } from '../util/context-util.js'; export class BackgroundDynamoLogTableHandler { dynamo; tableName; env; backgroundQueueName; constructor(dynamo, tableName, env, backgroundQueueName) { this.dynamo = dynamo; this.tableName = tableName; this.env = env; this.backgroundQueueName = backgroundQueueName; } async onEvent(event) { const entry = { env: this.env, backgroundQueueName: this.backgroundQueueName, requestId: ContextUtil.currentRequestId(), guid: event.guid, processTypeName: event.processorType, state: event.type.toString(), timestampEpochMs: new Date().getTime(), }; if (event.type == BackgroundExecutionEventType.DataValidationError) { const errors = event?.errors?.length ? event.errors : ['No-Error']; entry.errors = errors; } else if (event.type == BackgroundExecutionEventType.ProcessStarting) { entry.params = event.data; } else if (event.type == BackgroundExecutionEventType.ExecutionFailedError) { const errors = event?.errors?.length ? event.errors : ['No-Error']; entry.errors = errors; } await this.dynamo.simplePut(this.tableName, entry); } } //# sourceMappingURL=background-dynamo-log-table-handler.js.map