MCPcopy
hub / github.com/breejs/bree / add

Method add

src/index.js:684–728  ·  view source on GitHub ↗
(jobs)

Source from the content-addressed store, hash-verified

682 }
683
684 async add(jobs) {
685 debug('add', jobs);
686
687 if (!this._init) await this.init();
688
689 //
690 // make sure jobs is an array
691 //
692 if (!Array.isArray(jobs)) {
693 jobs = [jobs];
694 }
695
696 const errors = [];
697 const addedJobs = [];
698
699 await Promise.all(
700 // handle `jobs` in case it is a Set or an Array
701 // <https://stackoverflow.com/a/42624575>
702 [...jobs].map(async (job_, index) => {
703 try {
704 const names = [
705 ...getJobNames(jobs, index),
706 ...getJobNames(this.config.jobs)
707 ];
708
709 await validateJob(job_, index, names, this.config);
710 const job = buildJob(job_, this.config);
711
712 addedJobs.push(job);
713 } catch (err) {
714 errors.push(err);
715 }
716 })
717 );
718
719 debug('jobs added', this.config.jobs);
720
721 // If there were any errors then throw them
722 if (errors.length > 0) {
723 throw combineErrors(errors);
724 }
725
726 this.config.jobs.push(...addedJobs);
727 return addedJobs;
728 }
729
730 async remove(name) {
731 debug('remove', name);

Callers 2

index.jsFile · 0.80
add.jsFile · 0.80

Calls 3

initMethod · 0.95
getJobNamesFunction · 0.85
buildJobFunction · 0.85

Tested by

no test coverage detected