kelektiv / node-cron

Cron for NodeJS.
MIT License
8.46k stars 626 forks source link

Getting error date.format is not a function #636

Closed tbhaxor closed 1 year ago

tbhaxor commented 1 year ago

Description

I am getting the following error in the version v2.0.0

https://github.com/kelektiv/node-cron/blob/master/lib/time.js#L271

Cron expression I am using

CronExpression.EVERY_MINUTE

Screenshots

Screenshot_20221202_082404

Additional information

No response

radcapitalist commented 1 year ago

Same problem here. I'm at version 2.1.0. The crash is in this code here:

                // hard stop if the current date is after the expected execution
                if (Date.now() > timeout) {
                    throw new Error(
                        Something went wrong. It took over five seconds to find the next execution time for the cron job.
                            Please refer to the canonical issue (https://github.com/kelektiv/node-cron/issues/467) and provide the following string if you would like to help debug:
                            Time Zone: ${zone || '""'} - Cron String: ${this} - UTC offset: ${date.format(
                            'Z'
                        )} - current Date: ${luxon.DateTime.local().toString()}`
                    );
                }

Curious, @tbhaxor , if this happens every time for you or intermittently. For me, I'm getting this intermittently when running my unit tests when I ask for a bunch of next dates. I'll keep investigating.

Eric

ChrisTolmeijer commented 1 year ago

Running into this issue too. Programmatically starting a cron with 0 */5 * * * * as interval.

Screen Shot 2022-12-24 at 3 37 37 PM

For me it happens randomly so far. Need to catch this anyhow since it's apparently happening when it's already about to throw an exception. However, maybe the fact that this error is happening generating the error message is indicative of another underlying problem.

lk77 commented 1 year ago

i have the same issue it seems, and it's pretty random too

file:///storage/emulated/0/app/18d69ebda12db328db91.bundle.js TypeError: n.format is not a function
    at l._getNextDateFrom (file:///storage/emulated/0/app/18d69ebda12db328db91.bundle.js:2:258591)
    at l.sendAt (file:///storage/emulated/0/app/18d69ebda12db328db91.bundle.js:2:257749)
    at n.nextDates (file:///storage/emulated/0/app/18d69ebda12db328db91.bundle.js:2:255002)
    at t.startTask (file:///storage/emulated/0/app/18d69ebda12db328db91.bundle.js:2:106681)
    at t.addGlobalTasks (file:///storage/emulated/0/app/18d69ebda12db328db91.bundle.js:2:105620)
    at new t (file:///storage/emulated/0/app/18d69ebda12db328db91.bundle.js:2:105351)
    at t.mounted (file:///storage/emulated/0/app/18d69ebda12db328db91.bundle.js:2:107997)
    at s.e.init (file:///storage/emulated/0/app/18d69ebda12db328db91.bundle.js:2:99153)
    at Sr.<anonymous> (file:///storage/emulated/0/app/18d69ebda12db328db91.bundle.js:2:207994)
    at Array.<anonymous> (file:///storage/emulated/0/app/18d69ebda12db328db91.bundle.js:2:12362),vue-component-5-e,nextTick
tbhaxor commented 1 year ago

I have now moved on to different package https://www.npmjs.com/package/node-cron, it is working fine for me

intcreator commented 1 year ago

this is fixed in #630

barisusakli commented 1 year ago

Will there be a 2.2.1 with this fix?

intcreator commented 1 year ago

yeah, working on publishing to NPM. might be a 2.3.0 though since we've changed some heavier stuff as well

ledlamp commented 1 year ago

@barisusakli wow, my nodebb forum also broken as of 12h ago with this error. i wonder what happened! this code looks strange 🤨 https://github.com/kelektiv/node-cron/blob/03f94ad825009e26f58a63ce6316d811aff76990/lib/time.js#L262-L278

and #630 doesn't solve anything, it's still gonna throw the error ☹️ #408 #467 looks like it's been around for years and nobody knows what's wrong? 😦

intcreator commented 1 year ago

@ledlamp #467 is a pretty general error which can have a number of causes. basically any time the CPU lags too much the error can be thrown. this can be due to infinite loops, overloaded systems, etc. honestly we should close that issue and focus on issues that have specific causes. no program is perfect so it's unreasonable to expect that it will absolutely never fail