写入文件增加文件锁,避免竞争条件引起文件内容异常

This commit is contained in:
whyour
2025-01-04 01:22:29 +08:00
parent 7d43b14f81
commit 05f8bbd26e
13 changed files with 103 additions and 55 deletions
+2 -1
View File
@@ -21,6 +21,7 @@ import { spawn } from 'cross-spawn';
import dayjs from 'dayjs';
import pickBy from 'lodash/pickBy';
import omit from 'lodash/omit';
import { writeFileWithLock } from '../shared/utils';
@Service()
export default class CronService {
@@ -601,7 +602,7 @@ export default class CronService {
}
});
await fs.writeFile(config.crontabFile, crontab_string);
await writeFileWithLock(config.crontabFile, crontab_string);
execSync(`crontab ${config.crontabFile}`);
await CrontabModel.update({ saved: true }, { where: {} });