rbrahul / deno_cron

A cron Job scheduler for Deno that allows you to write human readable cron syntax with tons of flexibility
MIT License
100 stars 2 forks source link

Caught errors cause cronjob to die permanently #3

Closed FinlayDaG33k closed 3 years ago

FinlayDaG33k commented 3 years ago

hii there,

I have some cronjobs using this that rely on fetch to get some data from external APIs.
However, sometimes, the internet is offline during the moments these fetches happen.
I cleanly catch these errors like this:

cron('* * * * *', async () => {
  try {
    await this.update();
  } catch(e) {
    error(`Could not update Azur Lane server status: ${e.message}`);
  }
});

The console shows that it was caught just fine:

[ERR  @ 2021/05/20 13:25:05] Could not update Azur Lane server status: error sending request for url (http://blhxusgate.yo-star.com/?cmd=load_server?): error trying to connect: dns error: Device or resource busy (os error 16)

But the cronjob is never run after this again (the only way to fix it, is to re-register the job in the code or restart the Deno process all together).

rbrahul commented 3 years ago

Hi @FinlayDaG33k I have just tried to raise exception and handling it within the try-catch which worked as expected for me. Please have a look on these code and the output. This job executed on every 10th second even the job threw the exception.

693922E1-49A4-4A64-91E6-5F167FA7F294

Output:

15672DC0-3BE9-492A-A18F-10039D3D31FD

Please double check your exception handling, hope this example helps. Thank you. 🙂

FinlayDaG33k commented 3 years ago

Thanks for the reply.
I'll see if there is anything else in my code that may cause the issue. I'll close this issue for now and re-open it if the need arises :)

FinlayDaG33k commented 3 years ago

Durr, the issue was kinda stupid... I have a property in my class isRunning that prevents the check from running if it's still doing stuff....
But if the exception occurs during the fetch, this never gets set to false again, preventing the code from ever running again...