MCPcopy Create free account
hub / github.com/DialmasterOrg/Youtarr / addOrUpdateJob

Method addOrUpdateJob

server/modules/jobModule.js:431–458  ·  view source on GitHub ↗
(jobData, isNextJob = false)

Source from the content-addressed store, hash-verified

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

Callers 5

doSpecificDownloadsMethod · 0.80
startImportMethod · 0.80
jobModule.test.jsFile · 0.80

Calls 3

getInProgressJobIdMethod · 0.95
addJobMethod · 0.95
updateJobMethod · 0.95

Tested by

no test coverage detected