Skip to main content

index/classes/EventsBatcherService.md

Service for batching and flushing events to the backend

Usage:

const batcher = new EventsBatcherService(httpClient, {
batchSize: 20,
flushIntervalMs: 3000
});

batcher.track('token_buy', { tokenName: 'PEPE', amount: '100' });
await batcher.flush(); // Manual flush

Constructors​

Constructor​

new EventsBatcherService(httpClient, config?): EventsBatcherService

Parameters​

ParameterType
httpClientHttpClient
config?EventsConfig

Returns​

EventsBatcherService

Methods​

configure()​

configure(options): void

Configure batching options

Parameters​

ParameterType
optionsPartial<EventsConfig>

Returns​

void


flush()​

flush(): Promise<void>

Manually flush all buffered events

Returns​

Promise<void>


getStats()​

getStats(): EventsBatcherStats

Get current statistics

Returns​

EventsBatcherStats


shutdown()​

shutdown(timeoutMs?): Promise<void>

Graceful shutdown - flush remaining events

Parameters​

ParameterTypeDescription
timeoutMs?numberMax time to wait for flush (default: 5000)

Returns​

Promise<void>


track()​

track(eventType, payload, options?): void

Track an event

Parameters​

ParameterTypeDescription
eventTypestringType of event
payloadRecord<string, unknown>Event payload data
options?{ immediate?: boolean; sessionId?: string; tokenName?: string; userAddress?: string; }Optional tracking options
options.immediate?boolean-
options.sessionId?string-
options.tokenName?string-
options.userAddress?string-

Returns​

void