Skip to content

Instantly share code, notes, and snippets.

@thakursaurabh1998
Created June 27, 2022 19:39
Show Gist options
  • Save thakursaurabh1998/912d28e5065cc561483b29985557dc76 to your computer and use it in GitHub Desktop.
Save thakursaurabh1998/912d28e5065cc561483b29985557dc76 to your computer and use it in GitHub Desktop.
class Poll {
/**
* @typedef options
* @property {number} interval Interval between each poll in `seconds`
* @property {number} maxPollCount Max number of times to poll
*
* @param {options} options
* @param {(Object) => Promise<boolean>} pollingFunction
* @param {QueueClientInterface} queueClient
*/
constructor({ interval, maxPollCount }, pollingFunction, queueClient, logger = console) {
this.logger = logger;
this.interval = interval;
this.queueClient = queueClient;
this.maxPollCount = maxPollCount;
this.pollingFunction = pollingFunction;
// The DLQ pushes all the expired messages to the COLLECTOR_QUEUE
// and our consumer subscribes to this queue.
this.mq.listen('COLLECTOR_QUEUE', options);
this.mq.on('dequeue', (data) => {
this.fetchAndValidate(data);
});
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment