agreeable-caravan-87149
03/07/2024, 4:40 PMagreeable-caravan-87149
03/07/2024, 9:00 PM// Auxiliary functions and constants
const POLLING_INTERVAL_MS = 40000
const TIMEOUT_INTERVAL_SECONDS = 180
const wait = (ms = 1000) => {
return new Promise((resolve) => {
setTimeout(resolve, ms)
})
}
// Initialize query params
const query = `
query IngestAdhocContentStandalonePublication($id: uuid!) {
ingestAdhocContentStandalonePublication(id: $id) {
// --- redacted ---
}
}`
const variables = { id: workflow.ingestionId }
const config = {
headers: {
'Content-Type': 'application/json',
'x-api-key': env.backend_gql_api_key
}
}
if (workflow.ingestionStatus !== 'success' && workflow.ingestionStatus !== 'failed') {
// Poll ingestion processing job
const { data } = await axios.post(env.backend_gql_api_endpoint, { query, variables }, config)
if (data.data?.errors?.length > 0 || data.data?.ingestAdhocContentStandalonePublication?.output?.postId) {
if (data.data.errors?.length > 0) {
// Flag failed ingestion
workflow.ingestionStatus = 'failed'
} else {
// Store results in workflow variables
const { postId, title, publisher, description } = data.data.ingestAdhocContentStandalonePublication.output
workflow.postId = postId
workflow.title = title
workflow.publisher = publisher
workflow.description = description
workflow.ingestionStatus = 'success'
}
} else {
await wait(POLLING_INTERVAL_MS)
}
}
agreeable-caravan-87149
03/07/2024, 9:01 PMagreeable-caravan-87149
03/09/2024, 10:48 AM