From b13fb3c93bcf5bde6ac20044ed8a8afb8fc673dc Mon Sep 17 00:00:00 2001 From: Jacob Gillespie Date: Sat, 24 Feb 2024 11:15:16 +0000 Subject: [PATCH] Always send full state payloads --- src/handlers/state.ts | 41 ++++++++--------------------------------- 1 file changed, 8 insertions(+), 33 deletions(-) diff --git a/src/handlers/state.ts b/src/handlers/state.ts index d671d25..d1bcd61 100644 --- a/src/handlers/state.ts +++ b/src/handlers/state.ts @@ -7,7 +7,6 @@ import {sleep} from '../utils/common' import {CLOUD_AGENT_CONNECTION_ID} from '../utils/env' import {reportError} from '../utils/errors' import {client} from '../utils/grpc' -import {logger} from '../utils/logger' export async function startStateStream(signal: AbortSignal) { while (!signal.aborted) { @@ -44,37 +43,6 @@ interface StateCache { let stateCache: StateCache | null = null export async function reportCurrentState(currentState: CurrentState) { - if (stateCache) { - const diff = compare(stateCache.state, currentState) - - // If there is no difference, don't send a request - if (diff.length === 0) return - - const request: PlainMessage = { - connectionId: CLOUD_AGENT_CONNECTION_ID, - state: { - case: 'patch', - value: { - generation: stateCache.generation, - patch: { - case: 'aws', - value: { - patch: JSON.stringify(diff), - }, - }, - }, - }, - } - - try { - const res = await client.reportCurrentState(request) - stateCache = {state: currentState, generation: res.generation} - return - } catch { - // Ignore an error here and fall down to below - } - } - const request: PlainMessage = { connectionId: CLOUD_AGENT_CONNECTION_ID, state: { @@ -90,8 +58,15 @@ export async function reportCurrentState(currentState: CurrentState) { }, }, } + + if (stateCache) { + const diff = compare(stateCache.state, currentState) + + // If there is no difference, don't send a request + if (diff.length === 0) return + } + const res = await client.reportCurrentState(request) - logger.info('Saving state in cache') stateCache = {state: currentState, generation: res.generation} }