Emil
Emil2w ago

Deno.cron scheduled to run once daily executes 6 times daily

I have a cron job on Deno deploy that is supposed to send a Telegram message daily at 5:00. Each day at 5:00, I receive 6 messages.
4 Replies
Emil
Emil2w ago
await Deno.cron("send-name-day", "0 5 * * *", () => {
const nameDays = [ ... ];
const date = new Date();
const month = date.getMonth() + 1;
const day = date.getDate();
const nameDay = nameDays[month - 1][day - 1];

const path = `https://api.telegram.org/bot${Deno.env.get("TOKEN")}/sendMessage`;
const resp = fetch(path, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
chat_id: XXXXXXXXXX,
text: `${day}/${month}: ${nameDay}`,
}),
});
console.log(resp.json());
});
await Deno.cron("send-name-day", "0 5 * * *", () => {
const nameDays = [ ... ];
const date = new Date();
const month = date.getMonth() + 1;
const day = date.getDate();
const nameDay = nameDays[month - 1][day - 1];

const path = `https://api.telegram.org/bot${Deno.env.get("TOKEN")}/sendMessage`;
const resp = fetch(path, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
chat_id: XXXXXXXXXX,
text: `${day}/${month}: ${nameDay}`,
}),
});
console.log(resp.json());
});
Emil
Emil2w ago
No description
Emil
Emil2w ago
Any help would be greatly appreciated!
EthanThatOneKid
In the meantime, you can maybe try to store the last time a cron job was invoked in deno kv to prevent messages from being sent in succession.