Skip to content

Commit f755798

Browse files
committed
chore: add inline documentation
1 parent 7df321a commit f755798

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,13 +569,18 @@ class RetryQueue implements IQueue<QueueItemData> {
569569
const firstAttemptedAt = inProgressItem?.firstAttemptedAt ?? now;
570570
const lastAttemptedAt = inProgressItem?.lastAttemptedAt ?? now;
571571

572-
// A decimal integer representing the seconds since the last attempt
572+
// A decimal integer representing the seconds since the first attempt
573573
const timeSinceFirstAttempt = Math.round((now - firstAttemptedAt) / 1000);
574+
575+
// A decimal integer representing the seconds since the last attempt
574576
const timeSinceLastAttempt = Math.round((now - lastAttemptedAt) / 1000);
577+
578+
// Indicates if the item has been reclaimed from local storage
575579
const reclaimed = inProgressItem?.reclaimed ?? false;
576580

577-
// Update the last attempted at timestamp for the in progress item
581+
// Update the first attempted at timestamp for the in progress item
578582
inProgressItem.firstAttemptedAt = firstAttemptedAt;
583+
// Update the last attempted at to current timestamp for the in progress item
579584
inProgressItem.lastAttemptedAt = now;
580585

581586
inProgress[el.id] = inProgressItem;
@@ -669,6 +674,7 @@ class RetryQueue implements IQueue<QueueItemData> {
669674
type: el.type ?? type,
670675
firstAttemptedAt: el.firstAttemptedAt,
671676
lastAttemptedAt: el.lastAttemptedAt,
677+
// Mark the item as reclaimed from local storage
672678
reclaimed: true,
673679
});
674680
trackMessageIds.push(id);
@@ -695,6 +701,7 @@ class RetryQueue implements IQueue<QueueItemData> {
695701
this.enqueue({
696702
...el,
697703
id,
704+
// Mark the item as reclaimed from local storage
698705
reclaimed: true,
699706
type: el.type ?? SINGLE_QUEUE_ITEM_TYPE,
700707
time: this.schedule.now(),

packages/analytics-js-plugins/src/xhrQueue/utilities.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,25 @@ const getRequestInfo = (
9393
url = eventUrl;
9494
}
9595

96-
// Add sentAt header
96+
// Add current timestamp as sentAt header
97+
// The same value is added in the event payload as well
9798
headers.SentAt = currentTime;
99+
100+
// Add a header to indicate if the item has been reclaimed from
101+
// local storage
98102
if (qItemProcessInfo.reclaimed) {
99103
headers.Reclaimed = 'true';
100104
}
101105

102-
// Add retry headers if the item is being retried
106+
// Add retry headers if the item is being retried for delivery
103107
if (qItemProcessInfo.retryAttemptNumber > 0) {
108+
// The number of times this item has been attempted to retry
104109
headers['Retry-Attempt'] = qItemProcessInfo.retryAttemptNumber.toString();
110+
111+
// The number of seconds since the last attempt
105112
headers['Retried-After'] = qItemProcessInfo.timeSinceLastAttempt.toString();
113+
114+
// The number of seconds since the first attempt
106115
headers['Retried-After-First'] = qItemProcessInfo.timeSinceFirstAttempt.toString();
107116
}
108117

0 commit comments

Comments
 (0)