Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,30 @@ export const QUICK_WATCH_POLL_INTERVAL_MS = 300
export type BulkOperation = NonNullable<GetBulkOperationByIdQuery['bulkOperation']>

export async function shortBulkOperationPoll(adminSession: AdminSession, operationId: string): Promise<BulkOperation> {
const startTime = Date.now()
const poller = pollBulkOperation({
adminSession,
operationId,
pollIntervalSeconds: QUICK_WATCH_POLL_INTERVAL_MS / 1000,
})
return renderSingleTask<BulkOperation>({
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(
Expand Down
Loading