Skip to content

Commit

Permalink
code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Moumita Mandal committed Dec 24, 2021
1 parent 7ac1bac commit feab8f5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
4 changes: 2 additions & 2 deletions utils/EventRepository.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-lonely-if */
/* eslint-disable class-methods-use-this */
import logger from "./logUtil";
import xhrQueue from "./xhrModule";
import XHRQueue from "./xhrModule";
import BeaconQueue from "./storage/beaconQueue";
import { getCurrentTimeFormatted } from "./utils";

Expand Down Expand Up @@ -50,7 +50,7 @@ class EventRepository {
queueOptions = options.queueOptions;
}
targetUrl = this.url;
this.queue = xhrQueue;
this.queue = new XHRQueue();
}
this.queue.init(targetUrl, queueOptions, this.writeKey);
}
Expand Down
47 changes: 24 additions & 23 deletions utils/xhrModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,29 @@ class XHRQueue {
// TODO: add checks for value - has to be +ve?
Object.assign(queueOptions, options);
}
this.payloadQueue = new Queue("rudder", queueOptions, function (
item,
done
) {
// apply sentAt at flush time and reset on each retry
item.message.sentAt = getCurrentTimeFormatted();
// send this item for processing, with a callback to enable queue to get the done status
// eslint-disable-next-line no-use-before-define
xhrQueue.processQueueElement(
item.url,
item.headers,
item.message,
10 * 1000,
// eslint-disable-next-line consistent-return
function (err, res) {
if (err) {
return done(err);
this.payloadQueue = new Queue(
"rudder",
queueOptions,
function (item, done) {
// apply sentAt at flush time and reset on each retry
item.message.sentAt = getCurrentTimeFormatted();
// send this item for processing, with a callback to enable queue to get the done status
// eslint-disable-next-line no-use-before-define
this.processQueueElement(
item.url,
item.headers,
item.message,
10 * 1000,
// eslint-disable-next-line consistent-return
function (err, res) {
if (err) {
return done(err);
}
done(null, res);
}
done(null, res);
}
);
});
);
}.bind(this)
);

// start queue
this.payloadQueue.start();
Expand Down Expand Up @@ -111,5 +112,5 @@ class XHRQueue {
}
}

const xhrQueue = new XHRQueue();
export default xhrQueue;
// const xhrQueue = new XHRQueue();
export default XHRQueue;

0 comments on commit feab8f5

Please sign in to comment.