Change removal logic

This commit is contained in:
Cameron Paczek 2023-02-15 12:33:32 -08:00
parent 680b53c29b
commit 046535397a

View File

@ -28,8 +28,8 @@ const createCronService = () => {
const fnWithStrapi = (...args) => fn({ strapi }, ...args); const fnWithStrapi = (...args) => fn({ strapi }, ...args);
const job = new Job(null, fnWithStrapi); const job = new Job(taskValue.name || null, fnWithStrapi);
jobsSpecs.push({ job, options }); jobsSpecs.push({ job, options, name: taskValue.name });
if (running) { if (running) {
job.schedule(options); job.schedule(options);
@ -38,9 +38,9 @@ const createCronService = () => {
return this; return this;
}, },
remove(name) { remove(name) {
const matchingJobsSpecs = jobsSpecs.filter(({ options }) => options.name === name); const matchingJobsSpecs = jobsSpecs.filter(({ name: jobSpecName }) => jobSpecName === name);
matchingJobsSpecs.forEach(({ job }) => job.cancel()); matchingJobsSpecs.forEach(({ job }) => job.cancel());
jobsSpecs = jobsSpecs.filter(({ options }) => options.name !== name); jobsSpecs = jobsSpecs.filter(({ name: jobSpecName }) => jobSpecName !== name);
return this; return this;
}, },
start() { start() {