diff --git a/packages/app/src/cli/services/bulk-operations/watch-bulk-operation.test.ts b/packages/app/src/cli/services/bulk-operations/watch-bulk-operation.test.ts index c573fd8fa2..5dfb9a98c8 100644 --- a/packages/app/src/cli/services/bulk-operations/watch-bulk-operation.test.ts +++ b/packages/app/src/cli/services/bulk-operations/watch-bulk-operation.test.ts @@ -171,7 +171,7 @@ describe('watchBulkOperation', () => { }) }) -describe('quickWatchBulkOperation', () => { +describe('shortBulkOperationPoll', () => { const mockAdminSession = {token: 'test-token', storeFqdn: 'test.myshopify.com'} const operationId = 'gid://shopify/BulkOperation/123' @@ -206,6 +206,9 @@ describe('quickWatchBulkOperation', () => { beforeEach(() => { vi.mocked(sleep).mockResolvedValue() + vi.mocked(renderSingleTask).mockImplementation(async ({task}) => { + return task(() => {}) + }) }) test('returns immediately when operation is already completed', async () => { diff --git a/packages/app/src/cli/services/bulk-operations/watch-bulk-operation.ts b/packages/app/src/cli/services/bulk-operations/watch-bulk-operation.ts index 273c7383b1..0c44c3497f 100644 --- a/packages/app/src/cli/services/bulk-operations/watch-bulk-operation.ts +++ b/packages/app/src/cli/services/bulk-operations/watch-bulk-operation.ts @@ -22,23 +22,30 @@ export const QUICK_WATCH_POLL_INTERVAL_MS = 300 export type BulkOperation = NonNullable export async function shortBulkOperationPoll(adminSession: AdminSession, operationId: string): Promise { - const startTime = Date.now() - const poller = pollBulkOperation({ - adminSession, - operationId, - pollIntervalSeconds: QUICK_WATCH_POLL_INTERVAL_MS / 1000, - }) + return renderSingleTask({ + title: outputContent`Starting bulk operation...`, + task: async () => { + const startTime = Date.now() + const poller = pollBulkOperation({ + adminSession, + operationId, + pollIntervalSeconds: QUICK_WATCH_POLL_INTERVAL_MS / 1000, + useAdaptivePolling: false, + }) - let latestOperationState: BulkOperation | undefined + let latestOperationState: BulkOperation | undefined - do { - // eslint-disable-next-line no-await-in-loop - const {value, done} = await poller.next() - latestOperationState = value - if (done) return latestOperationState - } while (Date.now() - startTime < QUICK_WATCH_TIMEOUT_MS) + do { + // eslint-disable-next-line no-await-in-loop + const {value, done} = await poller.next() + latestOperationState = value + if (done) return latestOperationState + } while (Date.now() - startTime < QUICK_WATCH_TIMEOUT_MS) - return latestOperationState + return latestOperationState + }, + renderOptions: {stdout: process.stderr}, + }) } export async function watchBulkOperation(