Skip to content

Commit 4ca8e9a

Browse files
simple progress tracking
1 parent d7e721b commit 4ca8e9a

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

packages/store/src/cli/commands/store/execute.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ export default class Execute extends Command {
9393

9494
if (operationType === 'query') {
9595
this.log('starting bulk query...')
96-
const results = await runBulkQuery(query, adminSession)
96+
const results = await runBulkQuery(query, adminSession, (status, objectCount) => {
97+
this.log(`status: ${status} | objects: ${objectCount}`)
98+
})
99+
this.log('\nresults:')
97100
this.log(results)
98101
} else {
99102
this.error('bulk mutations not yet implemented')

packages/store/src/cli/services/bulk-operations.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ interface BulkOperationStatus {
4343
export async function runBulkQuery(
4444
query: string,
4545
session: AdminSession,
46+
onProgress?: (status: string, objectCount: string) => void,
4647
): Promise<string> {
4748
const startResult = await adminRequest<any>(BULK_QUERY_MUTATION, session, {query})
4849

@@ -51,16 +52,34 @@ export async function runBulkQuery(
5152
throw new Error(`bulk operation failed: ${errors}`)
5253
}
5354

55+
console.log('bulk operation started', startResult.bulkOperationRunQuery.bulkOperation.id)
56+
57+
let lastStatus = ''
58+
5459
while (true) {
55-
await sleep(1000)
60+
await sleep(1)
61+
62+
console.log('polling bulk operation status')
5663

5764
const statusResult = await adminRequest<BulkOperationStatus>(BULK_OPERATION_STATUS_QUERY, session)
5865
const operation = statusResult.currentBulkOperation
5966

67+
if (operation.status !== lastStatus && onProgress) {
68+
onProgress(operation.status, operation.objectCount)
69+
lastStatus = operation.status
70+
}
71+
72+
if (operation.status === 'RUNNING' && onProgress) {
73+
onProgress(operation.status, operation.objectCount)
74+
}
75+
6076
if (operation.status === 'COMPLETED') {
6177
if (!operation.url) {
6278
throw new Error('bulk operation completed but no results url')
6379
}
80+
if (onProgress) {
81+
onProgress('DOWNLOADING', operation.objectCount)
82+
}
6483
const response = await fetch(operation.url)
6584
return await response.text()
6685
}

0 commit comments

Comments
 (0)