Closed toymachiner62 closed 8 years ago
@toymachiner62 Not throwing errors was a deliberate design decision. You can still check the validity by ensuring that create()
didn't return null and job.isValid() == true
Interesting. What is the reason for allowing invalid syntax? I'm just curious.
On Sunday, November 8, 2015, Blagovest Dachev notifications@github.com wrote:
@toymachiner62 https://github.com/toymachiner62 Not throwing errors was a deliberate design decision. You can still check the validity by ensuring that create() didn't return null and job.isValid() == true
— Reply to this email directly or view it on GitHub https://github.com/dachev/node-crontab/pull/18#issuecomment-154929143.
Tom Caflisch 507.202.0087 TomCaflisch@gmail.com http://allthingswebdesign.com
create()
does not allow invalid syntax, it simply chooses to return a null instead of throwing an exception.
Also, validation capabilities should not be overestimated. There are many versions and flavors of crontab, each with its own options and supported syntax.
I suppose that's fair since we check for job === null && !job.isValid()
.
I haven used this module in a while but this should work :-)
require('crontab').load(function(err, crontab) {
var jobs = crontab.jobs();
for (var i = 0; i < jobs.length; i++) {
crontab.remove(jobs[0]);
}
crontab.save(function(err, crontab) {
});
});
Let me know if it doesn't and I'll look into making this possible.
That worked like a charm. Thanks!
No problem.
When creating a cronjob with an invalid syntax, it used to just return null, so a user wouldn't know why the cron job was not created.
I've modified this so it now throws an error when there is an invalid cronjob trying to be created so the user knows what the issue is.