) => {
const requestedIdentity = identity;
- setBusyPod(entry.podId);
+ const { podId } = entry;
+ const next = { ...entry, ...changes };
+ // An agent switch replaces these objects. Hold the ones this save started
+ // with, so a loop still in flight for the old agent never writes into the
+ // new agent's queue.
+ const committed = committedRef.current;
+ const queued = queuedRef.current;
+ const sending = sendingRef.current;
+ if (!committed[podId]) committed[podId] = entry;
+ queued[podId] = next;
+ setBusyPod(podId);
setError(null);
+ // Show the pick at once, so the next arrow key moves on from it.
+ setInstallations((current) => current.map((item) => item.podId === podId ? next : item));
+ if (sending[podId]) return;
+ sending[podId] = true;
try {
- const next = { ...entry, ...changes };
- await updatePod(entry.podId, {
- wakeOnMessage: next.wakeOnMessage,
- boardWake: next.boardWake,
- humanOnly: next.humanOnly,
- heartbeatEnabled: next.heartbeatEnabled,
- heartbeatMinutes: next.heartbeatMinutes,
- });
- if (identityRef.current === requestedIdentity) {
- setInstallations((current) => current.map((item) => item.podId === entry.podId ? next : item));
+ while (queued[podId]) {
+ const target = queued[podId] as InstallationSettings;
+ queued[podId] = undefined;
+ try {
+ // eslint-disable-next-line no-await-in-loop
+ await updatePod(podId, {
+ wakeOnMessage: target.wakeOnMessage,
+ boardWake: target.boardWake,
+ humanOnly: target.humanOnly,
+ heartbeatEnabled: target.heartbeatEnabled,
+ heartbeatMinutes: target.heartbeatMinutes,
+ });
+ committed[podId] = target;
+ } catch (requestError) {
+ queued[podId] = undefined;
+ if (identityRef.current === requestedIdentity) {
+ const saved = committed[podId];
+ setInstallations((current) => current.map((item) => item.podId === podId ? saved : item));
+ setError((requestError as { response?: { status?: number } })?.response?.status === 403
+ ? t('agentSettings.forbidden') : t('agentSettings.saveError'));
+ }
+ }
}
- } catch (requestError) {
- if (identityRef.current === requestedIdentity) setError((requestError as { response?: { status?: number } })?.response?.status === 403
- ? t('agentSettings.forbidden') : t('agentSettings.saveError'));
} finally {
+ sending[podId] = false;
if (identityRef.current === requestedIdentity) setBusyPod(null);
}
};
@@ -136,16 +188,17 @@ const V2AgentWakePods: React.FC<{
{installations.map((entry) => (
{entry.podName}
-
- {entry.wakeOnMessage && }
+