Skip to content

Commit

Permalink
Add several minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Castro, Mario committed Mar 19, 2024
1 parent 79aacd3 commit 8b06598
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
6 changes: 3 additions & 3 deletions packages/framework-core/src/services/event-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ export class EventStore {
}

@Trace(TraceActionTypes.CUSTOM)
public async storeDispatchedEvent(eventEnvelope: EventEnvelope) {
public async storeDispatchedEvent(eventEnvelope: EventEnvelope): Promise<boolean | undefined> {
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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions packages/framework-types/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ export class BoosterConfig {

private rocketFunctionMap: Record<string, RocketFunction> = {}

// 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) {
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 5 additions & 4 deletions packages/framework-types/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,12 @@ export interface ProviderEventsLibrary {
): Promise<EntitySnapshotEnvelope>

/**
* 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<EventEnvelope>` 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<boolean>
}
Expand Down

0 comments on commit 8b06598

Please sign in to comment.