Skip to content

Commit

Permalink
fix: debugging storeSpaceUsageDelta (#440)
Browse files Browse the repository at this point in the history
Add logging to aid in debugging the error in the Store Space Usage Delta
(Staging env).
  • Loading branch information
fforbeck authored Nov 14, 2024
1 parent 0b8a3c5 commit 5e70497
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions billing/lib/ucan-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,19 @@ export const findSpaceUsageDeltas = messages => {
*/
export const storeSpaceUsageDeltas = async (deltas, ctx) => {
const spaceDiffResults = await Promise.all(deltas.map(async delta => {
console.log(`Processing delta for ${delta.resource}`)
const consumerList = await ctx.consumerStore.list({ consumer: delta.resource })
if (consumerList.error) return consumerList
if (consumerList.error) {
console.error(`Error listing consumers for ${delta.resource}: ${consumerList.error}`)
return consumerList
}

const diffs = []
// There should only be one subscription per provider, but in theory you
// could have multiple providers for the same consumer (space).
for (const consumer of consumerList.ok.results) {
const consumers = consumerList.ok.results
console.log(`Found ${consumers.length} consumers for ${delta.resource}`)
for (const consumer of consumers) {
diffs.push({
provider: consumer.provider,
subscription: consumer.subscription,
Expand All @@ -93,10 +99,14 @@ export const storeSpaceUsageDeltas = async (deltas, ctx) => {

const spaceDiffs = []
for (const res of spaceDiffResults) {
if (res.error) return res
if (res.error) {
console.error(`Error while processing space diffs: ${res.error}`)
return res
}
spaceDiffs.push(...res.ok)
}

console.log(`Total space diffs to store: ${spaceDiffs.length}`)
return ctx.spaceDiffStore.batchPut(spaceDiffs)
}

Expand Down

0 comments on commit 5e70497

Please sign in to comment.