-
-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Croner & PM2: try to "date set" make the callback be called 2 times #101
Comments
Interesting! Could you pass and print new Date().toISOString() to matchWildcard, to get the exact internal time of each execution. Something like const dayjs = require('dayjs');
const Cron = require("croner");
//Simple match wildcard function like: "aa" will match "a*" or "*a" or "**" but not "bb" or "b*"
function matchWildcard(str1, str2, /*+*/ nowIso) {
console.debug(nowIso); // +
if (typeof str1 != "string" || typeof str2 != "string")
return false;
if (str1.length != str2.length)
return false;
for (let i = 0; i < str1.length; i++) {
if (str1.at(i) != "*" && str2.at(i) != "*" && str1.at(i) != str2.at(i)) {
console.debug(`${str1} matchs ${str2} ?: FALSE`);
return false;
}
}
console.debug(`${str1} matchs ${str2} ?: TRUE`);
return true;
}
//My cron task running every minute
const job = Cron("0 */1 * ? * *", async () => {
let now = dayjs(),
nowIso = new Date().toISOString(); // +
let dayKey = now.format("HH:mm.DD-MM");
matchWildcard("12:00.27-**", dayKey, /* + */ nowIso);
}); Also, did you just change the date once, and after that croner started maing multiple double runs? Which version of Node? |
It seems like the clock in docker runs too fast, which makes the trigger run to early. Then, as the target time is not yet reached, it makes a new schedule for one second later, and runs again. Do you have the same problem running with node/pm2 on host machine? I can not replicate the behavior in any of the setups (host, pm2+host, pm2+docker). So it seems to be related to a specific version of something. However, I've published a new version (4.3.12) which supports time travel. Give it a try :) |
Reopen if the problem persist |
Fix caused more problems than it solved, so we're back to square one on this one |
@oom- Should be resolved in |
Hello,
I'm using pm2 to keep my services up and running and centralize logs.
I'm running actually a really simple piece of code in a docker container (basically theses commands appears in my
Dockerfile
):Here is my NodeJS code:
So I met this really strange error where if I run a bash in my docker and try to change the date (unsuccessfully), the croner job is going to start to execute the callback at 32:00 min and 32:59min (like one ate 00sec and one at 59 sec) or starting to has 1sec late.
I know this is a really specific case but I was wondering if it could hide something more deep.
The text was updated successfully, but these errors were encountered: