Skip to content

Commit

Permalink
feat: added more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
mbret committed Mar 17, 2024
1 parent 1243afc commit ca7b9d3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
22 changes: 16 additions & 6 deletions packages/api/src/functions/refreshMetadata/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,25 @@ const lambda: ValidatedEventAPIGatewayProxyEvent<typeof schema> = async (
})
})

const lockId = `metadata_${event.body.bookId}`
logger.info(`invoke for ${event.body.bookId}`)

const { alreadyLocked } = await lock(lockId, LOCK_MAX_DURATION_MN)
try {
const lockId = `metadata_${event.body.bookId}`

if (!alreadyLocked) {
const response = await client.send(command)
const { alreadyLocked } = await lock(lockId, LOCK_MAX_DURATION_MN)

logger.info(`${event.body.bookId}: command sent with success`)
logger.info(response)
if (!alreadyLocked) {
const response = await client.send(command)

logger.info(`${event.body.bookId}: command sent with success`)
logger.info(response)
} else {
logger.info(`${event.body.bookId} is already locked, ignoring!`)
}
} catch (error) {
logger.error(error)

throw error
}

return {
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/libs/supabase/lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,9 @@ export const lock = async (
return { alreadyLocked: false }
}

if (response.error) {
throw response.error
}

return { alreadyLocked: true }
}

0 comments on commit ca7b9d3

Please sign in to comment.