From 07541569c5b1a8cc03a6ab95f3a3d1b17d248488 Mon Sep 17 00:00:00 2001 From: whyour Date: Sun, 2 Jun 2024 11:08:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=20real=5Ftime=20=E5=8F=82=E6=95=B0=EF=BC=8C=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=20protobufjs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/cron.ts | 11 ++++++++--- back/services/schedule.ts | 2 +- back/services/subscription.ts | 13 ++++++++----- package.json | 2 +- pnpm-lock.yaml | 28 ++++++++++------------------ 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/back/services/cron.ts b/back/services/cron.ts index 55aeb557..2e607f75 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -435,7 +435,10 @@ export default class CronService { const logPath = `${uniqPath}/${logTime}.log`; const absolutePath = path.resolve(config.logPath, `${logPath}`); const cp = spawn( - `real_log_path=${logPath} real_time=true no_delay=true ${this.makeCommand(cron)}`, + `real_log_path=${logPath} no_delay=true ${this.makeCommand( + cron, + true + )}`, { shell: '/bin/bash' }, ); @@ -526,12 +529,14 @@ export default class CronService { } } - private makeCommand(tab: Crontab) { + private makeCommand(tab: Crontab, realTime?: boolean) { let command = tab.command.trim(); if (!command.startsWith(TASK_PREFIX) && !command.startsWith(QL_PREFIX)) { command = `${TASK_PREFIX}${tab.command}`; } - let commandVariable = `no_tee=true ID=${tab.id} `; + let commandVariable = `real_time=${Boolean(realTime)} no_tee=true ID=${ + tab.id + } `; if (tab.task_before) { commandVariable += `task_before='${tab.task_before .replace(/'/g, "'\\''") diff --git a/back/services/schedule.ts b/back/services/schedule.ts index 7c2c878f..47f1f591 100644 --- a/back/services/schedule.ts +++ b/back/services/schedule.ts @@ -13,7 +13,7 @@ import taskLimit from '../shared/pLimit'; import { spawn } from 'cross-spawn'; export interface ScheduleTaskType { - id: number; + id?: number; command: string; name?: string; schedule?: string; diff --git a/back/services/subscription.ts b/back/services/subscription.ts index 94b0e73e..a8c28ded 100644 --- a/back/services/subscription.ts +++ b/back/services/subscription.ts @@ -91,9 +91,9 @@ export default class SubscriptionService { this.taskCallbacks(doc), runImmediately, )); - } else { + } else if (doc.interval_schedule) { this.scheduleService.cancelIntervalTask(doc as any); - const { type, value } = doc.interval_schedule as any; + const { type, value } = doc.interval_schedule; needCreate && (await this.scheduleService.createIntervalTask( doc as any, @@ -256,7 +256,7 @@ export default class SubscriptionService { ); } - public async remove(ids: number[], query: any) { + public async remove(ids: number[], query: { force?: boolean }) { const docs = await SubscriptionModel.findAll({ where: { id: ids } }); for (const doc of docs) { await this.handleTask(doc, false); @@ -279,8 +279,11 @@ export default class SubscriptionService { public async getDb( query: FindOptions['where'], ): Promise { - const doc: any = await SubscriptionModel.findOne({ where: { ...query } }); - return doc && (doc.get({ plain: true }) as Subscription); + const doc = await SubscriptionModel.findOne({ where: { ...query } }); + if (!doc) { + throw new Error(`${JSON.stringify(query)} not found`); + } + return doc.get({ plain: true }); } public async run(ids: number[]) { diff --git a/package.json b/package.json index d4e2dc6d..f6477b5b 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "node-schedule": "^2.1.0", "nodemailer": "^6.7.2", "p-queue-cjs": "7.3.4", - "protobufjs": "^7.2.3", + "protobufjs": "^7.3.0", "pstree.remy": "^1.1.8", "reflect-metadata": "^0.1.13", "sequelize": "^6.25.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dc225576..07a559cd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,5 +1,9 @@ lockfileVersion: '6.0' +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + dependencies: '@grpc/grpc-js': specifier: ^1.8.13 @@ -89,8 +93,8 @@ dependencies: specifier: 7.3.4 version: 7.3.4 protobufjs: - specifier: ^7.2.3 - version: 7.2.3 + specifier: ^7.3.0 + version: 7.3.0 pstree.remy: specifier: ^1.1.8 version: 1.1.8 @@ -3930,7 +3934,7 @@ packages: '@types/long': 4.0.2 lodash.camelcase: 4.3.0 long: 4.0.0 - protobufjs: 7.2.3 + protobufjs: 7.3.0 yargs: 17.7.2 dev: false @@ -7386,7 +7390,7 @@ packages: normalize-path: 3.0.0 readdirp: 3.6.0 optionalDependencies: - fsevents: 2.3.2 + fsevents: 2.3.3 /chownr@2.0.0: resolution: {integrity: sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==} @@ -9360,19 +9364,11 @@ packages: resolution: {integrity: sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==} requiresBuild: true - /fsevents@2.3.2: - resolution: {integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==} - engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} - os: [darwin] - requiresBuild: true - optional: true - /fsevents@2.3.3: resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==} engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} os: [darwin] requiresBuild: true - dev: true optional: true /ftp@0.3.10: @@ -12834,8 +12830,8 @@ packages: long: 4.0.0 dev: true - /protobufjs@7.2.3: - resolution: {integrity: sha512-TtpvOqwB5Gdz/PQmOjgsrGH1nHjAQVCN7JG4A6r1sXRWESL5rNMAiRcBQlCAdKxZcAbstExQePYG8xof/JVRgg==} + /protobufjs@7.3.0: + resolution: {integrity: sha512-YWD03n3shzV9ImZRX3ccbjqLxj7NokGN0V/ESiBV5xWqrommYHYiihuIyavq03pWSGqlyvYUFmfoMKd+1rPA/g==} engines: {node: '>=12.0.0'} requiresBuild: true dependencies: @@ -16673,7 +16669,3 @@ packages: - encoding - supports-color dev: false - -settings: - autoInstallPeers: true - excludeLinksFromLockfile: false