Skip to content

Commit eff7d39

Browse files
committed
fix: update function name
1 parent 6e98978 commit eff7d39

File tree

7 files changed

+19
-14
lines changed

7 files changed

+19
-14
lines changed

billing/functions/billing-cron.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as Sentry from '@sentry/serverless'
22
import { expect } from './lib.js'
33
import { createCustomerStore } from '../tables/customer.js'
44
import { createCustomerBillingQueue } from '../queues/customer.js'
5-
import { startOfDay, startOfYesterday } from '../lib/util.js'
5+
import { startOfToday, startOfYesterday } from '../lib/util.js'
66
import { enqueueCustomerBillingInstructions } from '../lib/billing-cron.js'
77
import { mustGetEnv } from '../../lib/env.js'
88

@@ -38,7 +38,7 @@ export const handler = Sentry.AWSLambda.wrapHandler(
3838
// the sum of all daily usage records equals the total monthly usage for Stripe billing.
3939
let period = {
4040
from: startOfYesterday(now), // at 00:00 UTC
41-
to: startOfDay(now) // at 00:00 UTC
41+
to: startOfToday(now) // at 00:00 UTC
4242
}
4343

4444
if ('rawQueryString' in event) {

billing/lib/space-billing-queue.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const calculatePeriodUsage = async (instruction, ctx) => {
8080
console.log(`Total ${totalDiffs} diffs processed for space: ${instruction.space}...`)
8181
}
8282

83-
console.log(`Total size of ${instruction.space} is ${size} bytes @ ${instruction.to.toISOString()}`)
83+
console.log(`Final total size of ${instruction.space} is ${size} bytes and usage ${usage} byte/ms @ ${instruction.to.toISOString()}`)
8484

8585
return { ok: { size, usage } }
8686
}

billing/lib/util.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
export const GB = 1024 * 1024 * 1024
22

33
/** @param {string|number|Date} now */
4-
export const startOfDay = (now) => {
4+
export const startOfToday = (now) => {
55
const d = new Date(now)
66
d.setUTCHours(0, 0, 0, 0)
77
return d
88
}
99

1010
/** @param {string|number|Date} now */
1111
export const startOfYesterday = (now) => {
12-
const d = startOfDay(now)
12+
const d = startOfToday(now)
1313
d.setUTCDate(d.getUTCDate() - 1)
1414
return d
1515
}

billing/scripts/replay-usage-reporting.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import fs from 'node:fs'
2222
import { mustGetEnv } from '../../lib/env.js'
2323
import * as Usage from '../data/usage.js'
2424
import { reportUsage } from '../functions/usage-table.js'
25+
import { createUsageStore } from '../tables/usage.js'
2526

2627
dotenv.config({ path: '.env.local' })
2728

@@ -32,6 +33,7 @@ const customerIndex = args.indexOf('--customer')
3233
const CUSTOMER = customerIndex !== -1 ? args[customerIndex + 1] : undefined
3334

3435
const STORACHA_ENV = mustGetEnv('STORACHA_ENV')
36+
const AWS_REGION = mustGetEnv('AWS_REGION')
3537
const STRIPE_SECRET_KEY = mustGetEnv('STRIPE_SECRET_KEY')
3638
const USAGE_TABLE_NAME = `${STORACHA_ENV}-w3infra-usage`
3739

@@ -152,7 +154,10 @@ async function main() {
152154
const timestamp = new Date().toISOString().replace(/[.:]/g, '-')
153155
const errorsFilename = `./replay-failures-${timestamp}.jsonl`
154156

155-
const ctx = { stripe }
157+
const ctx = {
158+
stripe,
159+
usageStore: createUsageStore({ region: AWS_REGION }, { tableName: USAGE_TABLE_NAME })
160+
}
156161

157162
const records = CUSTOMER ? queryUsageRecordsForCustomer(CUSTOMER) : scanUsageRecords()
158163
for await (const usage of records) {

billing/test/lib/billing-cron.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { startOfYesterday, startOfDay } from '../../lib/util.js'
1+
import { startOfYesterday, startOfToday } from '../../lib/util.js'
22
import { enqueueCustomerBillingInstructions } from '../../lib/billing-cron.js'
33
import { randomCustomer } from '../helpers/customer.js'
44
import { collectQueueMessages } from '../helpers/queue.js'
@@ -19,7 +19,7 @@ export const test = {
1919
assert.ok(!error)
2020

2121
const now = new Date()
22-
const period = { from: startOfYesterday(now), to: startOfDay(now) }
22+
const period = { from: startOfYesterday(now), to: startOfToday(now) }
2323
const handled = await enqueueCustomerBillingInstructions(period, ctx)
2424
assert.ok(handled.ok)
2525

billing/test/lib/customer-billing-queue.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { enqueueSpaceBillingInstructions } from '../../lib/customer-billing-queue.js'
2-
import { startOfYesterday, startOfDay } from '../../lib/util.js'
2+
import { startOfYesterday, startOfToday } from '../../lib/util.js'
33
import { randomConsumer } from '../helpers/consumer.js'
44
import { randomCustomer } from '../helpers/customer.js'
55
import { collectQueueMessages } from '../helpers/queue.js'
@@ -40,7 +40,7 @@ export const test = {
4040
account: customer.account,
4141
product: customer.product,
4242
from: startOfYesterday(now),
43-
to: startOfDay(now)
43+
to: startOfToday(now)
4444
}
4545

4646
const handled = await enqueueSpaceBillingInstructions(instruction, ctx)

billing/test/lib/space-billing-queue.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { calculatePeriodUsage, storeSpaceUsage } from '../../lib/space-billing-queue.js'
2-
import { startOfYesterday, startOfDay } from '../../lib/util.js'
2+
import { startOfYesterday, startOfToday } from '../../lib/util.js'
33
import { randomConsumer } from '../helpers/consumer.js'
44
import { randomCustomer } from '../helpers/customer.js'
55
import { randomLink } from '../helpers/dag.js'
@@ -11,7 +11,7 @@ export const test = {
1111
const consumer = await randomConsumer()
1212
const now = new Date()
1313
const from = startOfYesterday(now)
14-
const to = startOfDay(now)
14+
const to = startOfToday(now)
1515
const delta = 1024 * 1024 * 1024 // 1GiB
1616

1717
await ctx.spaceDiffStore.batchPut([{
@@ -64,7 +64,7 @@ export const test = {
6464
const consumer = await randomConsumer()
6565
const now = new Date()
6666
const from = startOfYesterday(now)
67-
const to = startOfDay(now)
67+
const to = startOfToday(now)
6868
const delta = 1024 * 1024 * 1024 // 1GiB
6969

7070
await ctx.spaceSnapshotStore.put({
@@ -140,7 +140,7 @@ export const test = {
140140
const size = BigInt(1024 * 1024 * 1024 * 1024) // 1TiB
141141
const now = new Date()
142142
const from = startOfYesterday(now)
143-
const to = startOfDay(now)
143+
const to = startOfToday(now)
144144
const delta = 1024 * 1024 * 1024 // 1GiB
145145

146146
await ctx.spaceSnapshotStore.put({

0 commit comments

Comments
 (0)