Worker doesn't show any logs/Cron job fails when code is good

As strange as the title is, that's exactly what my issue is. My code is a simple discord tool and it's been running fine but suddenly decides to not do anything. I noticed it with when i was trying to implement a new feature and the code was broken and I saw the Exception logs - as expected, but when I fixed it, there would no longer be any logs, Real Time Logs page would just keep spinning on "Websocket connection established. Listening for events..." and that's it. Cron events page would show show the cron job erroring out but no logging is available.
wrangler tail
wrangler tail
doesn't return anything either. If I intentionally break the code again, I get the logs and everything, what's up with this exactly? At the moment, I've minimised the code to simply:
addEventListener("scheduled", (event) => {
event.waitUntil(handleScheduled(event));
});
async function handleScheduled(event) {
const originalCurrentTime = new Date(event.scheduledTime);
await sendToDiscord(DEBUG_CHANNEL, `Last triggered at: ${currentTime}`);
}

async function sendToDiscord(webhookUrl, message) {
// Send the message and get the response
// If the response is not 200, log the error
const response = await fetch(webhookUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ content: message }),
});

// Check if the response status is in the 200-204 range
if (response.status >= 200 && response.status <= 204) {
console.log("Message sent successfully to Discord.");
} else {
// If the response status is not in the success range, log the error
console.error(
`Error sending message to Discord. Status: ${response.status}, Message: ${message}`
);
// Also log the response body for further investigation
const responseBody = await response.text();
console.error(`Response Body: ${responseBody}`);
}
}
addEventListener("scheduled", (event) => {
event.waitUntil(handleScheduled(event));
});
async function handleScheduled(event) {
const originalCurrentTime = new Date(event.scheduledTime);
await sendToDiscord(DEBUG_CHANNEL, `Last triggered at: ${currentTime}`);
}

async function sendToDiscord(webhookUrl, message) {
// Send the message and get the response
// If the response is not 200, log the error
const response = await fetch(webhookUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ content: message }),
});

// Check if the response status is in the 200-204 range
if (response.status >= 200 && response.status <= 204) {
console.log("Message sent successfully to Discord.");
} else {
// If the response status is not in the success range, log the error
console.error(
`Error sending message to Discord. Status: ${response.status}, Message: ${message}`
);
// Also log the response body for further investigation
const responseBody = await response.text();
console.error(`Response Body: ${responseBody}`);
}
}
DEBUG_CHANNEL is just a webhook URL for test purposes. Am I missing something?
3 Replies
idkwhoiam322
idkwhoiam322OP7mo ago
It does randomly occasionally work for some reason, but I'd love to know what is breaking it potentially so I can deal with it from my end
Milli
Milli7mo ago
I'm encountering the same issue. Previous versions of my worker show that it works. A newly deployed worker no longer receives requests. The changes that were made to the code were limited to just renaming variables, types. Nothing that would break it.
idkwhoiam322
idkwhoiam322OP7mo ago
The strange part for me was if I intentionally broke the code it would give me lots so I didn't really understand.:NotLikeThis:
Want results from more Discord servers?
Add your server