(jobData, isNextJob = false)
| 429 | } |
| 430 | |
| 431 | async addOrUpdateJob(jobData, isNextJob = false) { |
| 432 | let jobId; |
| 433 | const inProgressJobId = this.getInProgressJobId(); |
| 434 | if (!isNextJob) { |
| 435 | if (inProgressJobId) { |
| 436 | // If there is a job in progress, create a new job with status Pending |
| 437 | logger.info({ jobType: jobData.jobType }, 'A job is already in progress. Adding job to the queue'); |
| 438 | jobData.status = 'Pending'; |
| 439 | jobId = await this.addJob(jobData); |
| 440 | } else { |
| 441 | // Otherwise, add a job with status In Progress |
| 442 | logger.info({ jobType: jobData.jobType }, 'Adding job to jobs list as In Progress'); |
| 443 | jobData.status = 'In Progress'; |
| 444 | jobId = await this.addJob(jobData); |
| 445 | } |
| 446 | } else if (isNextJob && !inProgressJobId) { |
| 447 | // If this is a next job and there's no job in progress, update its status to In Progress |
| 448 | logger.info('This is a "next job", flipping from Pending to In Progress'); |
| 449 | await this.updateJob(jobData.id, { |
| 450 | status: 'In Progress', |
| 451 | timeInitiated: Date.now(), |
| 452 | }); |
| 453 | jobId = jobData.id; |
| 454 | } else { |
| 455 | logger.warn('Cannot start next job as a job is already in progress'); |
| 456 | } |
| 457 | return jobId; |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | * Prepares video data for database save, setting last_downloaded_at if file is verified |
no test coverage detected