(jobs)
| 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); |
no test coverage detected