Skip to content

Commit

Permalink
feat: get updated import data at each step
Browse files Browse the repository at this point in the history
  • Loading branch information
tiago-freire committed Sep 3, 2024
1 parent cc77946 commit 2f10045
Showing 1 changed file with 2 additions and 30 deletions.
32 changes: 2 additions & 30 deletions node/helpers/setupVerifyImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ import {
getFirstImportPending,
getFirstImportRunning,
getFirstImportToBeDeleted,
IMPORT_STATUS,
updateImportStatus,
} from '.'
import runImport from '../events'

const TIMEOUT = 10000
let cachedContext: Context | undefined
let hasImportRun: boolean | undefined

export function getCachedContext() {
return cachedContext
Expand All @@ -20,22 +17,10 @@ export function setCachedContext(context: Context) {
cachedContext = context
}

export function setHasImportRun() {
hasImportRun = true
}

export function getHasImportRun() {
return hasImportRun
}

const verifyImports = async () => {
const context = getCachedContext()

if (!context) return

const importRunning = await getFirstImportRunning(context)

if (importRunning && getHasImportRun()) return
if (!context || (await getFirstImportRunning(context))) return

const nextImportToBeDeleted = await getFirstImportToBeDeleted(context)

Expand All @@ -45,23 +30,10 @@ const verifyImports = async () => {
return
}

const nextPendingImport =
importRunning && !getHasImportRun()
? importRunning
: await getFirstImportPending(context)
const nextPendingImport = await getFirstImportPending(context)

if (!nextPendingImport) return

setHasImportRun()

if (nextPendingImport.status === IMPORT_STATUS.RUNNING) {
await updateImportStatus(
context,
nextPendingImport.id,
IMPORT_STATUS.PENDING
)
}

context.state.body = nextPendingImport
runImport(context)
}
Expand Down

0 comments on commit 2f10045

Please sign in to comment.