-
Notifications
You must be signed in to change notification settings - Fork 26
/
fetch_costs_of_all_assemblies_in_timeframe.js
56 lines (46 loc) · 1.43 KB
/
fetch_costs_of_all_assemblies_in_timeframe.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Run this file as:
//
// env TRANSLOADIT_KEY=xxx TRANSLOADIT_SECRET=yyy node fetch_costs_of_all_assemblies_in_timeframe.js
//
// make sure to "npm install p-map" for this demo
const pMap = require('p-map')
// You'll likely just want to `require('transloadit')`, but we're requiring the local
// variant here for easier testing:
const Transloadit = require('../src/Transloadit')
const fromdate = '2020-12-31 15:30:00'
const todate = '2020-12-31 15:30:01'
;(async () => {
try {
const params = {
fromdate,
todate,
page: 1,
}
const transloadit = new Transloadit({
authKey: process.env.TRANSLOADIT_KEY,
authSecret: process.env.TRANSLOADIT_SECRET,
})
let totalBytes = 0
let lastCount
do {
console.log('Processing page', params.page)
const { count, items } = await transloadit.listAssemblies(params)
lastCount = count
params.page++
await pMap(
items,
// eslint-disable-next-line no-loop-func
async (assembly) => {
const assemblyFull = await transloadit.getAssembly(assembly.id)
// console.log(assemblyFull.assembly_id)
const { bytes_usage: bytesUsage } = assemblyFull
totalBytes += bytesUsage || 0
},
{ concurrency: 20 }
)
} while (lastCount > 0)
console.log('Total GB:', (totalBytes / (1024 * 1024 * 1024)).toFixed(2))
} catch (err) {
console.error(err)
}
})()