Better status reporting and handling of return codes

This commit is contained in:
2021-03-03 14:00:54 +00:00
parent 05b1260483
commit e6d47a7b62
2 changed files with 116 additions and 37 deletions

View File

@@ -47,7 +47,7 @@ router.delete('/queue/:id/:calcFn', function(req, res) {
})
// Get the status of a task as a text string
// Poll the status of a task as a text string
const processStatus = function(id, calcFn) {
if (calcQueueSvc.isInProgress(id, calcFn)) {
return 'in_progress'
@@ -60,6 +60,43 @@ const processStatus = function(id, calcFn) {
}
}
// Poll the status of an individual task
router.get('/poll/:id', function(req, res) {
const status = processStatus(req.params.id, null)
if (status == 'finished') {
res.status(statusCodes.OK).send({
id: req.params.id,
status: status,
retCode: calcQueueSvc.retCode(req.params.id, null)
})
} else {
res.status(statusCodes.OK).send({
id: req.params.id,
status: status
})
}
})
// Poll the status of an individual task
router.get('/poll/:id/:calcFn', function(req, res) {
const status = processStatus(req.params.id, req.params.calcFn)
if (status == 'finished') {
res.status(statusCodes.OK).send({
id: req.params.id,
calcFn: req.params.calcFn,
status: status,
retCode: calcQueueSvc.retCode(req.params.id, req.params.calcFn)
})
} else {
res.status(statusCodes.OK).send({
id: req.params.id,
calcFn: req.params.calcFn,
status: status
})
}
})
// Get the status of the queue and all tasks
router.get('/status', function(req, res) {
res.status(statusCodes.OK).send({
@@ -71,19 +108,22 @@ router.get('/status', function(req, res) {
// Get the status of all tasks with by id
router.get('/status/:id', function(req, res) {
res.status(statusCodes.OK).send({
'id': req.params.id,
'status': processStatus(req.params.id, null)
})
const status = calcQueueSvc.getStatus(req.params.id, null)
if (status.length == 0) {
res.status(statusCodes.BAD_REQUEST).send()
} else {
res.status(statusCodes.OK).send(status)
}
})
// Get the status of an individual task
router.get('/status/:id/:calcFn', function(req, res) {
res.status(statusCodes.OK).send({
'id': req.params.id,
'calcFn': req.params.calcFn,
'status': processStatus(req.params.id, req.params.calcFn)
})
const status = calcQueueSvc.getStatus(req.params.id, req.params.calcFn)
if (status.length == 0) {
res.status(statusCodes.BAD_REQUEST).send()
} else {
res.status(statusCodes.OK).send(status)
}
})
module.exports = router