question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

job.stop() is not a function

See original GitHub issue

Hello, 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:open
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
japhendywijayacommented, Apr 29, 2021

use setImmediate( ()=>{ job.stop() })

0reactions
gyalbucommented, Jun 6, 2021

@japhendywijaya thanks. They should mention this in the docs

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found