@splitsoftware/splitio-commons
Version:
Split JavaScript SDK common components
24 lines (23 loc) • 1.24 kB
JavaScript
import { submitterFactory, firstPushWindowDecorator } from './submitter';
import { SUBMITTERS_PUSH_FULL_QUEUE } from '../../logger/constants';
/**
* Submitter that periodically posts tracked events
*/
export function eventsSubmitterFactory(params) {
var _a = params.settings, log = _a.log, eventsPushRate = _a.scheduler.eventsPushRate, eventsFirstPushWindow = _a.startup.eventsFirstPushWindow, postEventsBulk = params.serviceApi.postEventsBulk, events = params.storage.events;
// don't retry events.
var submitter = submitterFactory(log, postEventsBulk, events, eventsPushRate);
// Set a timer for the first push window of events.
if (eventsFirstPushWindow > 0)
submitter = firstPushWindowDecorator(submitter, eventsFirstPushWindow);
// register events submitter to be executed when events cache is full
events.setOnFullQueueCb(function () {
if (submitter.isRunning()) {
log.info(SUBMITTERS_PUSH_FULL_QUEUE, [events.name]);
submitter.execute();
}
// If submitter is stopped (e.g., user consent declined or unknown, or app state offline), we don't send the data.
// Data will be sent when submitter is resumed.
});
return submitter;
}