Background task: anvil.server.RuntimeUnavailableError: Internal server error: Server runtime failed to start

Hi,

I have an app with a scheduled task that runs a report once a month. This month the app failed because the server runtime could not start. I was thinking if I could do a while loop to retry until the server is connected again.

anvil.server.RuntimeUnavailableError: Internal server error: Server runtime failed to start.

I have noticed that the server is down now and then, so I thought that retrying until it is successful should solve the problem. How have you solved these problems?

How can I catch the anvil.server.RuntimeUnavailableError when I am executing a scheduled task?

The problem with that loop is that, if the server is down, it doesn’t run the loop.

A solution would be to schedule the task 2-3 times, 2 hours apart, and start by checking if the report has already been generated. The first run creates the report, the second and third check, find the report and immediately exit, unless the first failed.

(I have plenty of nightly reports, either scheduled in the app or triggered by other schedulers that call Anvil http endpoints. I had only one failure that I remember in years of usage, and I’ve never implemented anything similar.)

1 Like

Thanks for the tip @stefano.menci, I did not think of the loop not starting if the server is down.

Do you have any tip of where I could store a variable that the report has been generated? I do the report in another system and I could check the timestamp of it there, but I would rather prefer to have the variable stored in Anvil if possible.

Now that I think of it, I could store the variable in the database and check if from there. But - Can I check the variable if the server is down?

If the server is down nothing happens, and there will be another try after two hours.

If the report is stored in a data table, you can add a timestamp column and check that. Otherwise you can create a table with one column with one row, containing the timestamp of the last successful report.

As I mentioned earlier, I have plenty of nightly, weekly or monthly report generators, and I’ve never done anything similar. Instead I have a Generate report button on some apps, so the user can start the report generation on demand if something went wrong. Some reports are fast, some are slower, and I’ve never heard a complaint.

Most of our failures are caused by other resources involved in the report generation (the Domino server a few scripts import from, file transfers from or to SharePoint, CAD scripts, etc.), not by Anvil server down. I consider that an exceptional event and I don’t plan for it.

1 Like