(script: ScriptRunResource)
| 88 | } |
| 89 | |
| 90 | async enableScript(script: ScriptRunResource) { |
| 91 | // 开启脚本 |
| 92 | // 如果正在运行,先释放 |
| 93 | if (this.execScriptMap.has(script.uuid)) { |
| 94 | await this.disableScript(script.uuid); |
| 95 | } |
| 96 | const metadataStr = getMetadataStr(script.code) || ""; |
| 97 | const userConfigStr = getUserConfigStr(script.code) || ""; |
| 98 | const userConfig = parseUserConfig(userConfigStr); |
| 99 | const loadScript = { |
| 100 | ...script, |
| 101 | metadataStr, |
| 102 | userConfigStr, |
| 103 | userConfig, |
| 104 | } as ScriptLoadInfo; |
| 105 | if (script.type === SCRIPT_TYPE_BACKGROUND) { |
| 106 | // 后台脚本直接运行起来 |
| 107 | return this.execScript(loadScript); |
| 108 | } else { |
| 109 | // 定时脚本加入定时任务 |
| 110 | this.stopCronJob(script.uuid); |
| 111 | return this.crontabScript(loadScript); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | async disableScript(uuid: string) { |
| 116 | // 关闭脚本 |
nothing calls this directly
no test coverage detected