* Start single monitor
()
| 190 | * Start single monitor |
| 191 | */ |
| 192 | async startMonitor() { |
| 193 | const monitor = this.monitor; |
| 194 | const { interval } = monitor; |
| 195 | |
| 196 | const nextAction = () => { |
| 197 | if (this.isStopped === true) { |
| 198 | return; |
| 199 | } |
| 200 | |
| 201 | this.timer = setTimeout(() => { |
| 202 | run(); |
| 203 | }, interval * 1000); |
| 204 | }; |
| 205 | |
| 206 | const run = async () => { |
| 207 | try { |
| 208 | await this.runMonitor(); |
| 209 | } catch (err) { |
| 210 | createAuditLog({ |
| 211 | workspaceId: this.monitor.workspaceId, |
| 212 | relatedId: this.monitor.id, |
| 213 | relatedType: 'Monitor', |
| 214 | content: `Run monitor(id: ${monitor.id}) error: ${String(err)}`, |
| 215 | }); |
| 216 | } finally { |
| 217 | nextAction(); |
| 218 | } |
| 219 | }; |
| 220 | |
| 221 | this.isStopped = false; |
| 222 | run(); |
| 223 | |
| 224 | logger.info(`Start monitor ${monitor.name}(${monitor.id})`); |
| 225 | } |
| 226 | |
| 227 | stopMonitor() { |
| 228 | const monitor = this.monitor; |
no test coverage detected