Merge branch 'develop' into abort-fix
This commit is contained in:
@@ -952,21 +952,40 @@ router.delete('/schedule/:id', requireSignIn, async (req: AuthenticatedRequest,
|
||||
*/
|
||||
router.post('/runs/abort/:id', requireSignIn, async (req: AuthenticatedRequest, res) => {
|
||||
try {
|
||||
if (!req.user) {
|
||||
return res.status(401).send({ error: 'Unauthorized' });
|
||||
}
|
||||
|
||||
const run = await Run.findOne({
|
||||
where: {
|
||||
runId: req.params.id,
|
||||
runByUserId: req.user.id,
|
||||
}
|
||||
});
|
||||
|
||||
if (!req.user) { return res.status(401).send({ error: 'Unauthorized' }); }
|
||||
|
||||
const run = await Run.findOne({ where: { runId: req.params.id } });
|
||||
|
||||
if (!run) {
|
||||
return res.status(404).send({ error: 'Run not found' });
|
||||
}
|
||||
|
||||
if (!['running', 'queued'].includes(run.status)) {
|
||||
return res.status(400).send({
|
||||
error: `Cannot abort run with status: ${run.status}`
|
||||
});
|
||||
}
|
||||
|
||||
const isQueued = run.status === 'queued';
|
||||
|
||||
await run.update({
|
||||
status: 'aborting'
|
||||
});
|
||||
|
||||
if (isQueued) {
|
||||
await run.update({
|
||||
status: 'aborted',
|
||||
finishedAt: new Date().toLocaleString(),
|
||||
log: 'Run aborted while queued'
|
||||
});
|
||||
|
||||
return res.send({
|
||||
success: true,
|
||||
message: 'Queued run aborted',
|
||||
isQueued: true
|
||||
});
|
||||
}
|
||||
|
||||
if (!['running', 'queued'].includes(run.status)) {
|
||||
return res.status(400).send({
|
||||
error: `Cannot abort run with status: ${run.status}`
|
||||
@@ -997,12 +1016,13 @@ router.post('/runs/abort/:id', requireSignIn, async (req: AuthenticatedRequest,
|
||||
|
||||
logger.log('info', `Abort signal sent for run ${req.params.id}, job ID: ${jobId}`);
|
||||
|
||||
return res.send({
|
||||
success: true,
|
||||
return res.send({
|
||||
success: true,
|
||||
message: 'Abort signal sent',
|
||||
jobId
|
||||
});
|
||||
|
||||
jobId,
|
||||
isQueued: false
|
||||
});
|
||||
|
||||
} catch (e) {
|
||||
const { message } = e as Error;
|
||||
logger.log('error', `Error aborting run ${req.params.id}: ${message}`);
|
||||
|
||||
Reference in New Issue
Block a user