job.stop() is not a function
See original GitHub issueHello, I’m having problems to ‘persist’ a job inside an array and them removing them.
I have this class. I store all jobs, when I create them, inside an array (this.jobs). Later, when I’m trying to remove (find the job, destroy it and remove from the array), I have job.stop() is not a function. But if I console.log(job), I can see the task and the destroy & stop functions.
What am I doing wrong? Is this the best way to “store” a job?
var cron = require("node-cron");
class JobStorage {
constructor() {
this.jobs = [];
this.identificator = 0;
}
add(cronTime) {
const id = this.identificator;
const job = cron.schedule(
cronTime,
function() {
console.log(`[${id}]: Hello from job!`);
},
{
scheduled: true,
timezone: "America/Sao_Paulo"
}
);
this.jobs.push({ job, jobId: id });
this.identificator++;
}
remove(id) {
const job = this.jobs.find(job => job.jobId === id);
job.stop();
job.destroy();
this.jobs = this.jobs.filter(job => job.jobId !== id);
}
logIds() {
console.log(this.jobs);
}
getJobs() {
return this.jobs;
}
}
module.exports = new JobStorage();
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
Top Results From Across the Web
How to fix 'stop.at is not a function' error? - Stack Overflow
5 it's ok, but v3 say "stop.at is not a function" when I try define the gradient. <svg id="svg1"> </svg> var draw =...
Read more >TypeError: "x" is not a function - JavaScript - MDN Web Docs
The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value...
Read more >JavaScript: Uncaught TypeError: n is not a function
This error occurs if you try to execute a function that is not initialized or is not initialized correctly. This means that the...
Read more >19 Functions | R for Data Science - Hadley Wickham
Functions allow you to automate common tasks in a more powerful and general way than... ... and throw an error (with stop() ),...
Read more >Uncaught TypeError | Is Not A Function | Solution - YouTube
Have you encountered an error like:- Uncaught TypeError- Some selector is not a function - jQuery is not a function - owlCarousel is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
use setImmediate( ()=>{ job.stop() })
@japhendywijaya thanks. They should mention this in the docs