diff --git a/back/services/cron.ts b/back/services/cron.ts index 48b9b3af..3bbba6aa 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -82,7 +82,7 @@ export default class CronService { } public async run(_id: string) { - this.cronDb.find({ _id }).exec((err, docs) => { + this.cronDb.find({ _id }).exec((err, docs: Crontab[]) => { let res = docs[0]; this.logger.silly('Running job'); @@ -92,7 +92,13 @@ export default class CronService { let logFile = `${config.manualLogPath}${res._id}.log`; fs.writeFileSync(logFile, `${new Date().toString()}\n\n`); - const cmd = spawn(`${res.command} now`, { shell: true }); + let cmdStr = res.command; + if (res.command.startsWith('js')) { + cmdStr = `${res.command} now`; + } else if (/&& (.*) >>/.test(res.command)) { + cmdStr = res.command.match(/&& (.*) >>/)[1]; + } + const cmd = spawn(cmdStr, { shell: true }); this.cronDb.update({ _id }, { $set: { status: CrontabStatus.running } }); @@ -141,7 +147,13 @@ export default class CronService { const tabs = await this.crontabs(); var crontab_string = ''; tabs.forEach((tab) => { - if (tab.status !== CrontabStatus.disabled) { + if (tab.status === CrontabStatus.disabled) { + crontab_string += '# '; + crontab_string += tab.schedule; + crontab_string += ' '; + crontab_string += this.make_command(tab); + crontab_string += '\n'; + } else { crontab_string += tab.schedule; crontab_string += ' '; crontab_string += this.make_command(tab); diff --git a/src/pages/crontab/index.tsx b/src/pages/crontab/index.tsx index 2147bb83..b559aa7d 100644 --- a/src/pages/crontab/index.tsx +++ b/src/pages/crontab/index.tsx @@ -123,11 +123,12 @@ const Crontab = () => { const [loading, setLoading] = useState(true); const [isModalVisible, setIsModalVisible] = useState(false); const [editedCron, setEditedCron] = useState(); + const [searchText, setSearchText] = useState(''); - const getCrons = (text: string = '') => { + const getCrons = () => { setLoading(true); request - .get(`${config.apiPrefix}crons?searchValue=${text}`) + .get(`${config.apiPrefix}crons?searchValue=${searchText}`) .then((data: any) => { setValue(data.data.sort((a: any, b: any) => a.status - b.status)); }) @@ -311,9 +312,13 @@ const Crontab = () => { }; const onSearch = (value: string) => { - getCrons(value); + setSearchText(searchText); }; + useEffect(() => { + getCrons(); + }, [searchText]); + useEffect(() => { if (document.body.clientWidth < 768) { setWdith('auto');