Comments (6)
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?
from croner.
Ok so I updated the code with a little extra line and info:
const dayjs = require('dayjs');
const Cron = require("croner");
let counter = 0;
//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]:", 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 () => {
console.log(`---------------------------NEW CALL: ${counter++}--------------------------`)
let now = dayjs(),
nowIso = new Date().toISOString();
let dayKey = now.format("HH:mm.DD-MM");
matchWildcard("12:00.27-**", dayKey, nowIso);
});
Seems that now even without trying to type date set
I get 2 calls :
0|main | 2022-05-30T09:09:00: ---------------------------NEW CALL: 0--------------------------
0|main | 2022-05-30T09:09:00: [NOWISO]: 2022-05-30T09:09:00.006Z
0|main | 2022-05-30T09:09:00: 12:00.27-** matchs 09:09.30-05 ?: FALSE
0|main | 2022-05-30T09:09:59: ---------------------------NEW CALL: 1--------------------------
0|main | 2022-05-30T09:09:59: [NOWISO]: 2022-05-30T09:09:59.995Z
0|main | 2022-05-30T09:09:59: 12:00.27-** matchs 09:09.30-05 ?: FALSE
0|main | 2022-05-30T09:10:00: ---------------------------NEW CALL: 2--------------------------
0|main | 2022-05-30T09:10:00: [NOWISO]: 2022-05-30T09:10:00.002Z
0|main | 2022-05-30T09:10:00: 12:00.27-** matchs 09:10.30-05 ?: FALSE
0|main | 2022-05-30T09:10:59: ---------------------------NEW CALL: 3--------------------------
0|main | 2022-05-30T09:10:59: [NOWISO]: 2022-05-30T09:10:59.996Z
0|main | 2022-05-30T09:10:59: 12:00.27-** matchs 09:10.30-05 ?: FALSE
0|main | 2022-05-30T09:11:00: ---------------------------NEW CALL: 4--------------------------
0|main | 2022-05-30T09:11:00: [NOWISO]: 2022-05-30T09:11:00.001Z
0|main | 2022-05-30T09:11:00: 12:00.27-** matchs 09:11.30-05 ?: FALSE
As you can see the CALL 15
and CALL 16
are following each other at 1 sec.
I do not have the issue if pm2 stop all
and restart it with node main.js
directly. :/
Edit: version of node is node:16.15-bullseye-slim
from croner.
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 :)
from croner.
Reopen if the problem persist
from croner.
Fix caused more problems than it solved, so we're back to square one on this one
from croner.
@oom- Should be resolved in 4.3.14
, please verify
from croner.
Related Issues (20)
- Whether seven-bit cron expressions are supported ? HOT 2
- Syntax error is service wroker HOT 2
- Cron runs every second instead of every 5 minutes. HOT 1
- Cron Job doesn't run correctly HOT 3
- L5,6 Day of the Week is not working correctly - L is not a number HOT 5
- Croner returns different values in case of trailing whitespace HOT 2
- Race HOT 4
- Fix and add the examples links HOT 1
- Request: Last day minus X HOT 1
- Bug: Increment not work as I expected HOT 3
- Specifying timezone causes no trigger using croner <= 7.x HOT 9
- previousRun and currentRun return null all the time HOT 5
- Using */59 * * * * * make run function twice HOT 1
- Support for modulo operator
- Specific timezones cause high CPU load on UNIX systems using croner <= 7.x HOT 10
- Storing job constant in mongo Db results in error HOT 1
- [Feature Request]: A way to stop all scheduled jobs, but wait for running jobs to complete HOT 2
- Job won't run when scheduled with America/Anchorage time zone HOT 1
- Events Feature request HOT 1
- Allow update HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from croner.