Skip to content

Commit 43bda24

Browse files
committed
Add user display during short poll
1 parent fb8280d commit 43bda24

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

packages/app/src/cli/services/bulk-operations/watch-bulk-operation.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe('watchBulkOperation', () => {
143143
})
144144
})
145145

146-
describe('quickWatchBulkOperation', () => {
146+
describe('shortBulkOperationPoll', () => {
147147
const mockAdminSession = {token: 'test-token', storeFqdn: 'test.myshopify.com'}
148148
const operationId = 'gid://shopify/BulkOperation/123'
149149

@@ -178,6 +178,9 @@ describe('quickWatchBulkOperation', () => {
178178

179179
beforeEach(() => {
180180
vi.mocked(sleep).mockResolvedValue()
181+
vi.mocked(renderSingleTask).mockImplementation(async ({task}) => {
182+
return task(() => {})
183+
})
181184
})
182185

183186
test('returns immediately when operation is already completed', async () => {

packages/app/src/cli/services/bulk-operations/watch-bulk-operation.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,25 @@ export const QUICK_WATCH_POLL_INTERVAL_MS = 300
2020
export type BulkOperation = NonNullable<GetBulkOperationByIdQuery['bulkOperation']>
2121

2222
export async function shortBulkOperationPoll(adminSession: AdminSession, operationId: string): Promise<BulkOperation> {
23-
const startTime = Date.now()
24-
const poller = pollBulkOperation(adminSession, operationId, QUICK_WATCH_POLL_INTERVAL_MS / 1000)
23+
return renderSingleTask<BulkOperation>({
24+
title: outputContent`Checking bulk operation status...`,
25+
task: async () => {
26+
const startTime = Date.now()
27+
const poller = pollBulkOperation(adminSession, operationId, QUICK_WATCH_POLL_INTERVAL_MS / 1000)
2528

26-
let latestOperationState: BulkOperation | undefined
29+
let latestOperationState: BulkOperation | undefined
2730

28-
do {
29-
// eslint-disable-next-line no-await-in-loop
30-
const {value, done} = await poller.next()
31-
latestOperationState = value
32-
if (done) return latestOperationState
33-
} while (Date.now() - startTime < QUICK_WATCH_TIMEOUT_MS)
31+
do {
32+
// eslint-disable-next-line no-await-in-loop
33+
const {value, done} = await poller.next()
34+
latestOperationState = value
35+
if (done) return latestOperationState
36+
} while (Date.now() - startTime < QUICK_WATCH_TIMEOUT_MS)
3437

35-
return latestOperationState
38+
return latestOperationState
39+
},
40+
renderOptions: {stdout: process.stderr},
41+
})
3642
}
3743

3844
export async function watchBulkOperation(

0 commit comments

Comments
 (0)