-
-
Notifications
You must be signed in to change notification settings - Fork 9
Description
What version of Elysia is running?
elysia: 1.1.17, @elysiajs/cron: 1.1.1
What platform is your computer?
Darwin 22.5.0 x86_64 i386
What steps can reproduce the bug?
Happens sporadically, not able to directly reproduce it.
Often when getting back to my terminal after my mac has been in sleep (server kept running), I see things like this:
running cron at 2024-10-12T22:16:46.083Z on PID 97232
running cron at 2024-10-12T22:16:46.245Z on PID 97232
running cron at 2024-10-12T22:16:46.260Z on PID 97232
running cron at 2024-10-12T22:16:46.068Z on PID 97232
running cron at 2024-10-12T22:16:46.083Z on PID 97232
running cron at 2024-10-12T22:16:46.095Z on PID 97232
running cron at 2024-10-12T22:16:46.109Z on PID 97232
running cron at 2024-10-12T22:16:46.118Z on PID 97232
running cron at 2024-10-12T22:16:46.127Z on PID 97232
running cron at 2024-10-12T22:16:46.139Z on PID 97232
running cron at 2024-10-12T22:16:46.150Z on PID 97232
running cron at 2024-10-12T22:16:46.162Z on PID 97232
Executing (default): UPDATE "SomeTable" SET [...]
Executing (default): UPDATE "SomeTable" SET [...]
Executing (default): UPDATE "SomeTable" SET [...]
Executing (default): UPDATE "SomeTable" SET [...]
Executing (default): UPDATE "SomeTable" SET [...]
Executing (default): UPDATE "SomeTable" SET [...]
Executing (default): UPDATE "SomeTable" SET [...]
Executing (default): UPDATE "SomeTable" SET [...]
Executing (default): UPDATE "SomeTable" SET [...]
Executing (default): UPDATE "SomeTable" SET [...]
Executing (default): UPDATE "SomeTable" SET [...]
Executing (default): UPDATE "SomeTable" SET [...]
I added logging meta data to understand better when this is happening. This is my cron-related code:
.use(
cron({
name: 'some_task',
pattern: '0 0 0 * * *',
run() {
const now = new Date();
console.log(`running cron at ${now.toISOString()} on PID ${process.pid}`);
try {
void someSqlRelatedTask();
} catch (error) {
console.error(error);
}
}
})
)
The first thing you notice is that the task doesn't run at midnight but rather at 22:16:46. And it's getting triggered 12 times. I don't know if this only happens when my mac is on sleep. I believe I've seen this happening before also when it wasn't asleep.
I've had this issue ever since I've started using the cron plugin (earlier versions).
What is the expected behavior?
A cron task should only run once per defined timestamp.
What do you see instead?
Cron task is run 12 times and at wrong timestamp.