Skip to content

Commit

Permalink
Merge pull request #51803 from Expensify/neil-log-SequentialQueue
Browse files Browse the repository at this point in the history
[No QA] Log when persisted requests are removed or updated
  • Loading branch information
tylerkaraszewski authored Oct 31, 2024
2 parents 5c2ecb1 + cb1a717 commit 13b169a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/libs/Network/SequentialQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function process(): Promise<void> {
pause();
}

Log.info('[SequentialQueue] Removing persisted request because it was processed successfully.', false, {request: requestToProcess});
PersistedRequests.endRequestAndRemoveFromQueue(requestToProcess);
RequestThrottle.clear();
return process();
Expand All @@ -105,6 +106,7 @@ function process(): Promise<void> {
// On sign out we cancel any in flight requests from the user. Since that user is no longer signed in their requests should not be retried.
// Duplicate records don't need to be retried as they just mean the record already exists on the server
if (error.name === CONST.ERROR.REQUEST_CANCELLED || error.message === CONST.ERROR.DUPLICATE_RECORD) {
Log.info("[SequentialQueue] Removing persisted request because it failed and doesn't need to be retried.", false, {error, request: requestToProcess});
PersistedRequests.endRequestAndRemoveFromQueue(requestToProcess);
RequestThrottle.clear();
return process();
Expand All @@ -114,6 +116,7 @@ function process(): Promise<void> {
.then(process)
.catch(() => {
Onyx.update(requestToProcess.failureData ?? []);
Log.info('[SequentialQueue] Removing persisted request because it failed too many times.', false, {error, request: requestToProcess});
PersistedRequests.endRequestAndRemoveFromQueue(requestToProcess);
RequestThrottle.clear();
return process();
Expand Down
4 changes: 4 additions & 0 deletions src/libs/actions/PersistedRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ let ongoingRequest: Request | null = null;
Onyx.connect({
key: ONYXKEYS.PERSISTED_REQUESTS,
callback: (val) => {
Log.info('[PersistedRequests] hit Onyx connect callback', false, {isValNullish: val == null});
persistedRequests = val ?? [];

if (ongoingRequest && persistedRequests.length > 0) {
Expand Down Expand Up @@ -91,12 +92,15 @@ function deleteRequestsByIndices(indices: number[]) {

function update(oldRequestIndex: number, newRequest: Request) {
const requests = [...persistedRequests];
const oldRequest = requests.at(oldRequestIndex);
Log.info('[PersistedRequests] Updating a request', false, {oldRequest, newRequest, oldRequestIndex});
requests.splice(oldRequestIndex, 1, newRequest);
persistedRequests = requests;
Onyx.set(ONYXKEYS.PERSISTED_REQUESTS, requests);
}

function updateOngoingRequest(newRequest: Request) {
Log.info('[PersistedRequests] Updating the ongoing request', false, {ongoingRequest, newRequest});
ongoingRequest = newRequest;

if (newRequest.persistWhenOngoing) {
Expand Down

0 comments on commit 13b169a

Please sign in to comment.