mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 14:56:07 +08:00
修复spawn可能中断,修复token过期任务状态修改
This commit is contained in:
parent
71d7d3818f
commit
517fdcc8ec
|
@ -30,6 +30,13 @@ export default ({ app }: { app: Application }) => {
|
||||||
if (!headerToken && req.path && req.path === '/api/login') {
|
if (!headerToken && req.path && req.path === '/api/login') {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
const remoteAddress = req.socket.remoteAddress;
|
||||||
|
if (
|
||||||
|
remoteAddress === '::ffff:127.0.0.1' &&
|
||||||
|
req.path === '/api/crons/status'
|
||||||
|
) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
const err: any = new Error('UnauthorizedError');
|
const err: any = new Error('UnauthorizedError');
|
||||||
err['status'] = 401;
|
err['status'] = 401;
|
||||||
next(err);
|
next(err);
|
||||||
|
|
|
@ -211,18 +211,17 @@ export default class CronService {
|
||||||
cmdStr = `${cmdStr} now`;
|
cmdStr = `${cmdStr} now`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cp = spawn(cmdStr, { shell: true, detached: true });
|
const cp = exec(cmdStr, (err, stdout, stderr) => {
|
||||||
this.cronDb.update(
|
|
||||||
{ _id },
|
|
||||||
{ $set: { status: CrontabStatus.running, pid: cp.pid } },
|
|
||||||
);
|
|
||||||
cp.on('close', (code) => {
|
|
||||||
this.cronDb.update(
|
this.cronDb.update(
|
||||||
{ _id },
|
{ _id },
|
||||||
{ $set: { status: CrontabStatus.idle }, $unset: { pid: true } },
|
{ $set: { status: CrontabStatus.idle }, $unset: { pid: true } },
|
||||||
);
|
);
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
|
this.cronDb.update(
|
||||||
|
{ _id },
|
||||||
|
{ $set: { status: CrontabStatus.running, pid: cp.pid } },
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user