Skip to content

Commit

Permalink
GH-467 GH-478 GH-469 GH-470 GH-497 GH-498 - Allow soft warning when a…
Browse files Browse the repository at this point in the history
… hard error isn't required.

Signed-off-by: Nick Campbell <nicholas.j.campbell@gmail.com>
  • Loading branch information
ncb000gt committed May 27, 2020
1 parent 9a51726 commit 982063f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
6 changes: 4 additions & 2 deletions lib/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ function CronJob(CronTime, spawn) {
context,
runOnInit,
utcOffset,
unrefTimeout
unrefTimeout,
softTimeout
) {
var _cronTime = cronTime;
var argCount = 0;
Expand All @@ -54,12 +55,13 @@ function CronJob(CronTime, spawn) {
_cronTime = cronTime.cronTime;
utcOffset = cronTime.utcOffset;
unrefTimeout = cronTime.unrefTimeout;
softTimeout = cronTime.softTimeout || false;
}

this.context = context || this;
this._callbacks = [];
this.onComplete = fnWrap(onComplete);
this.cronTime = new CronTime(_cronTime, timeZone, utcOffset);
this.cronTime = new CronTime(_cronTime, timeZone, utcOffset, softTimeout);
this.unrefTimeout = unrefTimeout;

addCallback.call(this, fnWrap(onTick));
Expand Down
17 changes: 11 additions & 6 deletions lib/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ const RE_WILDCARDS = /\*/g;
const RE_RANGE = /^(\d+)(?:-(\d+))?(?:\/(\d+))?$/g;

function CronTime(luxon) {
function CT(source, zone, utcOffset) {
function CT(source, zone, utcOffset, softTimeout) {
this.source = source;
this.softTimeout = softTimeout;

if (zone) {
const dt = luxon.DateTime.fromObject({ zone: zone });
Expand Down Expand Up @@ -265,13 +266,17 @@ function CronTime(luxon) {

// hard stop if the current date is after the expected execution
if (Date.now() > timeout) {
throw new Error(
`Something went wrong. cron reached maximum iterations.
var msg = `Something went wrong. cron reached maximum iterations.
Please open an issue (https://github.com/kelektiv/node-cron/issues/new) and provide the following string
Time Zone: ${zone || '""'} - Cron String: ${this} - UTC offset: ${date.format(
'Z'
)} - current Date: ${luxon.DateTime.local().toString()}`
);
'Z'
)} - current Date: ${luxon.DateTime.local().toString()}`;

if (this.softTimeout) {
console.warn(msg);
} else {
throw new Error(msg);
}
}

if (
Expand Down

0 comments on commit 982063f

Please sign in to comment.