Skip to content

Commit

Permalink
chore: add documentation and fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
saikumarrs committed Mar 2, 2025
1 parent 656fec9 commit 46ae303
Showing 1 changed file with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ const sortByTime = (a: QueueItem, b: QueueItem) => a.time - b.time;

const RETRY_QUEUE = 'RetryQueue';

/**
* Constructs a RetryQueue backed by localStorage
*
* @constructor
* @param {String} name The name of the queue. Will be used to find abandoned queues and retry their items
* @param {Object} [opts] Optional argument to override `maxItems`, `maxAttempts`, `minRetryDelay, `maxRetryDelay`, `backoffFactor` and `backoffJitter`.
* @param {QueueProcessCallback} fn The function to call in order to process an item added to the queue
*/
class RetryQueue implements IQueue<QueueItemData> {
name: string;
id: string;
Expand All @@ -78,6 +70,17 @@ class RetryQueue implements IQueue<QueueItemData> {
reclaimEndVal?: Nullable<string>;
isPageAccessible: boolean;

/**
* Constructs a RetryQueue backed by localStorage
*
* @param {String} name The name of the queue. Will be used to find abandoned queues and retry their items
* @param {QueueOpts} [options] Optional argument to override `maxItems`, `maxAttempts`, `minRetryDelay, `maxRetryDelay`, `backoffFactor` and `backoffJitter`.
* @param {QueueProcessCallback} queueProcessCb The function to call in order to process an item added to the queue
* @param {IStoreManager} storeManager The store manager instance to use
* @param {StorageType} [storageType] The storage type to use. Defaults to LOCAL_STORAGE
* @param {ILogger} [logger] The logger to use
* @param {QueueBatchItemsSizeCalculatorCallback} [queueBatchItemsSizeCalculatorCb] The callback to use to calculate the size of items in the batch queue
*/
constructor(
name: string,
options: QueueOpts,
Expand Down Expand Up @@ -376,7 +379,7 @@ class RetryQueue implements IQueue<QueueItemData> {
(this.getStorageEntry(QueueStatuses.QUEUE) as Nullable<QueueItem<QueueItemData>[]>) ?? [];

if (this.maxItems > 1) {
queue = queue.slice(-(this.maxItems - 1));
queue = queue.slice(-(this.maxItems - 1));
} else {
queue = [];

Check warning on line 384 in packages/analytics-js-plugins/src/utilities/retryQueue/RetryQueue.ts

View check run for this annotation

Codecov / codecov/patch

packages/analytics-js-plugins/src/utilities/retryQueue/RetryQueue.ts#L384

Added line #L384 was not covered by tests
}
Expand Down Expand Up @@ -424,9 +427,8 @@ class RetryQueue implements IQueue<QueueItemData> {
* Adds an item to the retry queue
*
* @param {Object} qItem The item to process
* @param {Error} [error] The error that occurred during processing
*/
requeue(qItem: QueueItem<QueueItemData>, error?: Error) {
requeue(qItem: QueueItem<QueueItemData>) {
const { attemptNumber, item, type, id, firstAttemptedAt, lastAttemptedAt, reclaimed } = qItem;
// Increment the attempt number as we're about to retry
const attemptNumberToUse = attemptNumber + 1;
Expand Down Expand Up @@ -509,7 +511,7 @@ class RetryQueue implements IQueue<QueueItemData> {
this.setStorageEntry(QueueStatuses.IN_PROGRESS, inProgress);

if (err) {
this.requeue({ ...el, firstAttemptedAt, lastAttemptedAt }, err);
this.requeue({ ...el, firstAttemptedAt, lastAttemptedAt });
}
};

Expand Down Expand Up @@ -739,7 +741,7 @@ class RetryQueue implements IQueue<QueueItemData> {
// if the queue is abandoned, all the in-progress are failed. retry them immediately and increment the attempt#
addConcatQueue(their.inProgress, 1);

our.queue = our.queue.sort(sortByTime);
our.queue.sort(sortByTime);

this.setStorageEntry(QueueStatuses.QUEUE, our.queue);

Expand All @@ -750,7 +752,6 @@ class RetryQueue implements IQueue<QueueItemData> {
this.processHead();
}

// eslint-disable-next-line class-methods-use-this
clearQueueEntries(other: IStore, localStorageBackoff: number) {
this.removeStorageEntry(other, 0, localStorageBackoff);
}
Expand Down

0 comments on commit 46ae303

Please sign in to comment.