Skip to content

Commit a170b5a

Browse files
authored
Merge pull request #6700 from Shopify/12-09-user-display-during-short-poll
Add user display during short poll
2 parents 8f8b496 + a17b645 commit a170b5a

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
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
@@ -171,7 +171,7 @@ describe('watchBulkOperation', () => {
171171
})
172172
})
173173

174-
describe('quickWatchBulkOperation', () => {
174+
describe('shortBulkOperationPoll', () => {
175175
const mockAdminSession = {token: 'test-token', storeFqdn: 'test.myshopify.com'}
176176
const operationId = 'gid://shopify/BulkOperation/123'
177177

@@ -206,6 +206,9 @@ describe('quickWatchBulkOperation', () => {
206206

207207
beforeEach(() => {
208208
vi.mocked(sleep).mockResolvedValue()
209+
vi.mocked(renderSingleTask).mockImplementation(async ({task}) => {
210+
return task(() => {})
211+
})
209212
})
210213

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

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

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,30 @@ export const QUICK_WATCH_POLL_INTERVAL_MS = 300
2222
export type BulkOperation = NonNullable<GetBulkOperationByIdQuery['bulkOperation']>
2323

2424
export async function shortBulkOperationPoll(adminSession: AdminSession, operationId: string): Promise<BulkOperation> {
25-
const startTime = Date.now()
26-
const poller = pollBulkOperation({
27-
adminSession,
28-
operationId,
29-
pollIntervalSeconds: QUICK_WATCH_POLL_INTERVAL_MS / 1000,
30-
})
25+
return renderSingleTask<BulkOperation>({
26+
title: outputContent`Starting bulk operation...`,
27+
task: async () => {
28+
const startTime = Date.now()
29+
const poller = pollBulkOperation({
30+
adminSession,
31+
operationId,
32+
pollIntervalSeconds: QUICK_WATCH_POLL_INTERVAL_MS / 1000,
33+
useAdaptivePolling: false,
34+
})
3135

32-
let latestOperationState: BulkOperation | undefined
36+
let latestOperationState: BulkOperation | undefined
3337

34-
do {
35-
// eslint-disable-next-line no-await-in-loop
36-
const {value, done} = await poller.next()
37-
latestOperationState = value
38-
if (done) return latestOperationState
39-
} while (Date.now() - startTime < QUICK_WATCH_TIMEOUT_MS)
38+
do {
39+
// eslint-disable-next-line no-await-in-loop
40+
const {value, done} = await poller.next()
41+
latestOperationState = value
42+
if (done) return latestOperationState
43+
} while (Date.now() - startTime < QUICK_WATCH_TIMEOUT_MS)
4044

41-
return latestOperationState
45+
return latestOperationState
46+
},
47+
renderOptions: {stdout: process.stderr},
48+
})
4249
}
4350

4451
export async function watchBulkOperation(

0 commit comments

Comments
 (0)