()
| 403 | } |
| 404 | |
| 405 | async startNextJob() { |
| 406 | logger.info('Looking for next job to start'); |
| 407 | const jobs = this.getAllJobs(); |
| 408 | for (let id in jobs) { |
| 409 | if (jobs[id].status === 'Pending') { |
| 410 | jobs[id].id = id; |
| 411 | if (jobs[id].action) { |
| 412 | jobs[id].action(jobs[id], true); // Invoke the function |
| 413 | } else { |
| 414 | // Job is missing its action function (likely loaded from DB after restart) |
| 415 | logger.warn({ jobId: id, jobType: jobs[id].jobType }, |
| 416 | 'Cannot start pending job - missing action function, marking as Terminated'); |
| 417 | |
| 418 | await this.updateJob(id, { |
| 419 | status: 'Terminated', |
| 420 | output: 'Job could not be started after server restart', |
| 421 | }); |
| 422 | |
| 423 | // Try to start the next pending job |
| 424 | this.startNextJob(); |
| 425 | } |
| 426 | break; |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | async addOrUpdateJob(jobData, isNextJob = false) { |
| 432 | let jobId; |
no test coverage detected