diff --git a/packages/framework-core/src/services/event-store.ts b/packages/framework-core/src/services/event-store.ts index 03b084808..bd54e8ebf 100644 --- a/packages/framework-core/src/services/event-store.ts +++ b/packages/framework-core/src/services/event-store.ts @@ -74,14 +74,14 @@ export class EventStore { } @Trace(TraceActionTypes.CUSTOM) - public async storeDispatchedEvent(eventEnvelope: EventEnvelope) { + public async storeDispatchedEvent(eventEnvelope: EventEnvelope): Promise { const logger = getLogger(this.config, 'EventStore#storeDispatchedEvent') try { logger.debug('Storing event in the dispatched event store:', eventEnvelope) return await this.config.provider.events.storeDispatched(eventEnvelope, this.config) } catch (e) { - logger.error('Could not store dispatched event: ', eventEnvelope) - return + logger.debug('Could not store dispatched event. Continue its processing.', eventEnvelope) + return true } } diff --git a/packages/framework-provider-aws/src/library/events-adapter.ts b/packages/framework-provider-aws/src/library/events-adapter.ts index d35e178f1..0ef0781e7 100644 --- a/packages/framework-provider-aws/src/library/events-adapter.ts +++ b/packages/framework-provider-aws/src/library/events-adapter.ts @@ -190,7 +190,7 @@ async function persistEvent( } /** - * Dummy method that'll always return an empty array, since local provider won't be tracking dispatched events + * Dummy method that'll always return true, since local provider won't be tracking dispatched events */ export async function storeDispatchedEvent() { return true diff --git a/packages/framework-provider-azure/src/library/events-adapter.ts b/packages/framework-provider-azure/src/library/events-adapter.ts index dfbbbaea5..dad22ddd0 100644 --- a/packages/framework-provider-azure/src/library/events-adapter.ts +++ b/packages/framework-provider-azure/src/library/events-adapter.ts @@ -200,10 +200,11 @@ export async function storeDispatchedEvent( if (e.code === 409) { // If an item with the same ID already exists in the container, it will return a 409 status code. // See https://learn.microsoft.com/en-us/rest/api/cosmos-db/http-status-codes-for-cosmosdb - logger.warn('[EventsAdapter#storeDispatchedEvent] Event has already been dispatched', eventEnvelope.id) + logger.debug('[EventsAdapter#storeDispatchedEvent] Event has already been dispatched', eventEnvelope.id) + return false } else { logger.error('[EventsAdapter#storeDispatchedEvent] Error storing dispatched event', e) + return true } } - return false } diff --git a/packages/framework-provider-local/src/library/events-adapter.ts b/packages/framework-provider-local/src/library/events-adapter.ts index f8be41660..f722ab6db 100644 --- a/packages/framework-provider-local/src/library/events-adapter.ts +++ b/packages/framework-provider-local/src/library/events-adapter.ts @@ -110,7 +110,7 @@ export async function storeSnapshot( } /** - * Dummy method that'll always return an empty array, since local provider won't be tracking dispatched events + * Dummy method that'll always return true, since local provider won't be tracking dispatched events */ export async function storeDispatchedEvent() { return true diff --git a/packages/framework-types/src/config.ts b/packages/framework-types/src/config.ts index 3280b4d33..26a05a5e6 100644 --- a/packages/framework-types/src/config.ts +++ b/packages/framework-types/src/config.ts @@ -102,6 +102,9 @@ export class BoosterConfig { private rocketFunctionMap: Record = {} + // TTL for events stored in dispatched events table. Default to 5 minutes (i.e., 300 seconds). + public dispatchedEventsTtl = 300 + public registerRocketFunction(id: string, func: RocketFunction): void { const currentFunction = this.rocketFunctionMap[id] if (currentFunction) { @@ -244,9 +247,6 @@ export class BoosterConfig { } } } - - // TTL for events stored in dispatched events table. Default to 5 minutes (i.e., 300 seconds). - public dispatchedEventsTtl = 300 } interface ResourceNames { diff --git a/packages/framework-types/src/provider.ts b/packages/framework-types/src/provider.ts index 64d168b2c..c5481cca8 100644 --- a/packages/framework-types/src/provider.ts +++ b/packages/framework-types/src/provider.ts @@ -146,11 +146,12 @@ export interface ProviderEventsLibrary { ): Promise /** - * Stores events envelopes that have been dispatched in the dispatched events table + * Stores an event envelope that has been dispatched in the dispatched events table. * - * @param eventEnvelope - The `Array` to store - * @param config - The Booster configuration object - * @returns `true` if the dispatched event was stored, otherwise, returns `false` + * @param eventEnvelope - The `EventEnvelope` to store. + * @param config - The Booster configuration object. + * @returns `true` if the dispatched event was stored, `false` if the event already exists in the dispatched events + * table. Will return `true` on any other error and log error to console. */ storeDispatched(eventEnvelope: EventEnvelope, config: BoosterConfig): Promise }