Conversation
View stack outputs
|
travis
left a comment
There was a problem hiding this comment.
this seems right to me! I think we should start this after the next billing run on Feb 1, so I'd recommend merging first thing next week, testing for a couple days in staging and then pushing to prod
hannahhoward
left a comment
There was a problem hiding this comment.
It vaguely looks this wouldn't work for the first run for a new customer where there is no previous usage, but I don't have context on the larger system. Assuming this properly handles the first run where there is no previous usage, LGTM.
If not, please fix.
billing/functions/usage-table.js
Outdated
| } | ||
|
|
||
| if (recoveryResult.error?.name === 'RecordNotFound') { | ||
| console.error(`CRITICAL DATA LOSS: Cannot calculate usage delta. Manual investigation and correction required.' \n ${JSON.stringify({ |
There was a problem hiding this comment.
Are we certain this never happens? Should it just be set to zero in this case?
There was a problem hiding this comment.
I’m not sure this wouldn’t happen, I don’t think it’s impossible. Yes, I could return zero, but that would undercharge the user since we'd lose previous usage.
update: as we discussed, it's better to let it error out and handle the issue later. That way we can easily track where it failed.
billing/functions/usage-table.js
Outdated
| const cumulativeByteQuantity = Math.floor(new Big(usage.usage.toString()).div(duration).toNumber()) | ||
|
|
||
| // Query previous day's usage to calculate delta | ||
| const previousCumulativeUsage = await getPreviousUsage(usage, ctx) |
There was a problem hiding this comment.
what happens the very first time this runs? Is there a value for previous then?
There was a problem hiding this comment.
If it's the first time, we won't find anything in the usage table or Stripe, so we'll return zero.
c022df6 to
1d888e2
Compare
1d888e2 to
8439016
Compare
7fe6a18 to
c844d78
Compare
Stack outputs updated
|
According to this RFC#78
This PR updates the billing process to run daily, enabling more frequent snapshot generation, which should help reduce usage report timeouts, and allow for more regular reporting to Stripe.