Skip to content

Commit

Permalink
make event retry count configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
dhawal1248 authored and sayan-mitra committed Nov 3, 2020
1 parent 9777852 commit 66e9648
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
15 changes: 13 additions & 2 deletions analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const queryDefaults = {
*/
function enqueue(rudderElement, type) {
if (!this.eventRepository) {
this.eventRepository = EventRepository;
this.eventRepository = EventRepository();
}
this.eventRepository.enqueue(rudderElement, type);
}
Expand Down Expand Up @@ -78,7 +78,6 @@ class Analytics {
this.toBeProcessedArray = [];
this.toBeProcessedByIntegrationArray = [];
this.storage = Storage;
this.eventRepository = EventRepository;
this.sendAdblockPage = false;
this.sendAdblockPageOptions = {};
this.clientSuppliedCallbacks = {};
Expand Down Expand Up @@ -887,6 +886,18 @@ class Analytics {
this.registerCallbacks(true);
}

const queueOptions = {};
if (options) {
if (options.maxRetries) {
queueOptions.maxAttempts = options.maxRetries;
}
if (options.maxQueueSize) {
queueOptions.maxItems = options.maxQueueSize;
}
}

this.eventRepository = new EventRepository(queueOptions);

this.eventRepository.writeKey = writeKey;
if (serverUrl) {
this.eventRepository.url = serverUrl;
Expand Down
9 changes: 6 additions & 3 deletions utils/EventRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class EventRepository {
*Creates an instance of EventRepository.
* @memberof EventRepository
*/
constructor() {
constructor(options) {
this.eventsBuffer = [];
this.writeKey = "";
this.url = "";
Expand All @@ -51,6 +51,10 @@ class EventRepository {
// previous implementation
// setInterval(this.preaparePayloadAndFlush, FLUSH_INTERVAL_DEFAULT, this);

if (options) {
// TODO: add checks for value - has to be +ve?
Object.assign(queueOptions, options);
}
this.payloadQueue = new Queue("rudder", queueOptions, function (
item,
done
Expand Down Expand Up @@ -229,5 +233,4 @@ class EventRepository {
});
}
}
let eventRepository = new EventRepository();
export { eventRepository as EventRepository };
export { EventRepository };

0 comments on commit 66e9648

Please sign in to comment.