Skip to content
Snippets Groups Projects
Commit 01245719 authored by Audrey Hamelers's avatar Audrey Hamelers
Browse files

#1185

parent 54e21ffc
No related branches found
No related tags found
3 merge requests!380Pipeline changes,!379Build step added for the master branch,!378k8s release
......@@ -17,13 +17,18 @@ if (!process.env.ENABLE_CRONJOB_PUBLISHEDCHECK) {
}
;(async () => {
await checkJobStatus('published-check', async () => {
const beforeUpdate = Date.now()
await publishedCheck()
logger.info(
`Published check was finished in ${Date.now() - beforeUpdate} ms`,
)
})
await checkJobStatus(
'published-check',
async () => {
const beforeUpdate = Date.now()
await publishedCheck()
logger.info(
`Published check was finished in ${Date.now() - beforeUpdate} ms`,
)
},
// FTP healthcheck
true,
)
await NoteAccess.knex().destroy()
process.exit(0)
})()
......
const logger = require('@pubsweet/logger')
const superagent = require('superagent')
const config = require('config')
const { parseExpression } = require('cron-parser')
const { JobManager } = require('../xpub-model/')
const checkJobStatus = async (name, logic) => {
const { DATA_CENTER } = process.env
const { internalBaseUrl } = config.get('pubsweet-server')
const checkJobStatus = async (name, logic, ftp) => {
// Perform healthcheck
logger.info(`Running healthcheck`)
const url = `${internalBaseUrl}/healthcheck?datacenterName=${DATA_CENTER}&ftpExcluded=${
ftp ? 0 : 1
}`
try {
await superagent.get(url)
} catch {
logger.info('Healthcheck failed. Exiting.')
return false
}
// Get job status from the database
logger.info(`Checking ${name} status`)
const { running, lastPass, frequency } = await JobManager.find(name)
if (running) {
logger.info(`${name} is currently running.`)
logger.info(`${name} is already running. Exiting.`)
return false
}
// Check if next pass exists between lastPass and current time
......@@ -20,19 +37,20 @@ const checkJobStatus = async (name, logic) => {
await interval.next()
logger.info(`${name} scheduled. Running:`)
} catch (ignore) {
logger.info(`${name} not yet scheduled to run.`)
logger.info(`${name} not yet scheduled to run. Exiting.`)
return false
}
// Mark job as running
await JobManager.update({ name, running: true })
// Run job logic
let status = 'fail'
// Run job logic and update job table
try {
await logic()
status = 'pass'
} catch {
status = 'fail'
}
// Update status when job completes (or fails)
return JobManager.update({
name,
running: false,
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment