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.

A better way to create new CronJob

See original GitHub issue

I’m using node-cron with CoffeeScript and I have difficult using it.

This is the code how I create new CronJob

daily = new CronJob
  cromTime: '00 00 00 * * *'
  onTick: ->
    cronTask('daily')
  start: false

I follow the sample code in the README.md. https://github.com/ncb000gt/node-cron#for-good-measure ,And I think my code should be fine, but it’s not actually working. It will pops up error like this:

    source = this.source.replace(/[a-z]{1,3}/ig, function(alias){
                         ^
TypeError: Cannot call method 'replace' of undefined
    at Object.CronTime._parse (/.../node_modules/cron/lib/cron.js:173:26)

I have no idea what happen, so I look into the code of node-cron. It’s seems I cannot pass a JSON object for creating new CronJob Object. I’m not sure if this was the problem, But It should need to change. This is the code from connect-redis which I think is a better way to create new object:

 function RedisStore(options) {
    ...
    options = options || {};
    Store.call(this, options);
    this.prefix = null == options.prefix
      ? 'sess:'
      : options.prefix;

    this.client = options.client || new redis.createClient(options.port || options.socket, options.host, options);
    if (options.pass) {
      ...   
    }

    this.ttl =  options.ttl;
    ...
  };

There are many options to create a CronJob while only two attributes is required. And the current way to create a CronJob will make the code written in CofeeScript become really messy.

I hope you can consider changing it. Thank you.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ncb000gtcommented, Aug 28, 2013

All good. 😃 Glad to be a brick wall.

0reactions
remaerdcommented, Aug 28, 2013

Problem solved. So sorry about it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Set Up a Cron Job in Linux - phoenixNAP
1. The first five fields a b c d e specify the time/date and recurrence of the job. · 2. In the second...
Read more >
How To Add Jobs To cron Under Linux or UNIX - nixCraft
You need to use the crontab command to edit/create, install, deinstall or list the cron jobs in Vixie Cron. Each user can have...
Read more >
Cron Job: A Comprehensive Guide for Beginners 2023
For a webmaster, cron job is a powerful method to handle repetitive tasks. This article will cover the basic guidance of using cron...
Read more >
How do I set up a Cron job? - Ask Ubuntu
To add a cron job that runs as root, you can edit root's crontab by running sudo crontab -e . The most flexible...
Read more >
How to Create or Edit a crontab File - Oracle Help Center
Create a new crontab file, or edit an existing file. $ crontab -e [ username ] · Add command lines to the crontab...
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