Skip to content

Commit

Permalink
Merge pull request #69 from depot/logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobwgillespie authored Sep 25, 2023
2 parents 02c30ea + 08e215c commit cb9e10f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/handlers/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export async function startStateStream(signal: AbortSignal) {
try {
logger.info('Getting current AWS state to report')
let currentState = await getCurrentState()

logger.info('Reporting current AWS state')
await reportCurrentState(currentState)

logger.info('Getting desired state')
Expand Down Expand Up @@ -48,6 +50,7 @@ let stateCache: StateCache | null = null

export async function reportCurrentState(currentState: CurrentState) {
if (stateCache) {
logger.info('Computing state diff')
const diff = compare(stateCache.state, currentState)

// If there is no difference, don't send a request
Expand All @@ -70,8 +73,10 @@ export async function reportCurrentState(currentState: CurrentState) {
}

try {
logger.info('Sending state diff to API')
const res = await client.reportCurrentState(request)
stateCache = {state: currentState, generation: res.generation}
return
} catch {
// Ignore an error here and fall down to below
}
Expand All @@ -92,7 +97,9 @@ export async function reportCurrentState(currentState: CurrentState) {
},
},
}
logger.info('Sending full state to API')
const res = await client.reportCurrentState(request)
logger.info('Saving state in cache')
stateCache = {state: currentState, generation: res.generation}
}

Expand Down

0 comments on commit cb9e10f

Please sign in to comment.