Emil
Emil6mo 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.
5 Replies
Emil
EmilOP6mo 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
EmilOP6mo ago
No description
Emil
EmilOP6mo ago
Any help would be greatly appreciated!
EthanThatOneKid
EthanThatOneKid6mo ago
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.
Emil
EmilOP6mo ago
Moved this to Val Town and am using their cron functionality for scheduling. Would love to move it back to Deno Deploy eventually if the issue can be resolved.