Skip to content

Commit

Permalink
feat(gatsby-source-shopify): Add query runtime warning for CI environ…
Browse files Browse the repository at this point in the history
…ments (#36142)

* Add query runtime warning for CI environments

* Make timer better

(cherry picked from commit e90448f)
  • Loading branch information
imjoshin committed Aug 1, 2022
1 parent 32ad041 commit 8855d63
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/gatsby-source-shopify/src/create-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ export function createOperations(
}

async function finishLastOperation(): Promise<void> {
const queryStartTime = Date.now()
let lastWarningTime = queryStartTime
const baseWarningInterval = 60 * 1000
let warningInterval = baseWarningInterval
let warningCount = 0

let { currentBulkOperation } = await currentOperation()
if (currentBulkOperation && currentBulkOperation.id) {
if (!finishedStatuses.includes(currentBulkOperation.status)) {
Expand All @@ -68,6 +74,28 @@ export function createOperations(
while (!finishedStatuses.includes(currentBulkOperation.status)) {
await new Promise(resolve => setTimeout(resolve, 1000))
currentBulkOperation = (await currentOperation()).currentBulkOperation

// add warning for CI environments
if (
process.env.CI &&
Date.now() > lastWarningTime + warningInterval
) {
lastWarningTime = Date.now()
const runtime = Math.floor(
(lastWarningTime - queryStartTime) / 1000
)
gatsbyApi.reporter.warn(
`Operation ${currentBulkOperation.id} is still running after ${runtime} seconds with status "${currentBulkOperation.status}"`
)

// handle next interval, slowly increase time so we don't flood every minute
warningCount += 1
warningInterval =
warningCount <= 5
? baseWarningInterval
: baseWarningInterval * 2 * (warningCount - 5)
}

timer.setStatus(
`Polling operation ${currentBulkOperation.id} : ${currentBulkOperation.status}`
)
Expand Down

0 comments on commit 8855d63

Please sign in to comment.