A better way to create new CronJob
See original GitHub issueI’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:
- Created 10 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
All good. 😃 Glad to be a brick wall.
Problem solved. So sorry about it.