Skip to content

Commit

Permalink
Reply to /v1/purge before restoring the state
Browse files Browse the repository at this point in the history
Purging data is already a long operation and waiting the target state to
be restored before sending the response can cause the request to
timeout. With `reboot-required`, the response will never be sent
because a reboot will happen when restoring the state.

This change ensures the API response happens once purge is completed.

Change-type: patch
  • Loading branch information
pipex committed Jan 8, 2025
1 parent 1abac28 commit 188b34a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/device-api/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ export const doPurge = async (appId: number, force: boolean = false) => {
keepVolumes: false,
force,
});
// Restore user app after purge
currentState.local.apps[appId] = app;
await deviceState.applyIntermediateTarget(currentState);
logger.logSystemMessage('Purged data', { appId }, 'Purge data success');
} catch (err: any) {
logger.logSystemMessage(
Expand All @@ -163,7 +160,9 @@ export const doPurge = async (appId: number, force: boolean = false) => {
);
throw err;
} finally {
deviceState.triggerApplyTarget();
// Restore user app after purge. Do not wait for the result
currentState.local.apps[appId] = app;
void deviceState.applyIntermediateTarget(currentState);
}
};

Expand Down

0 comments on commit 188b34a

Please sign in to comment.