Background tasks limitations not lifted for personal plan

Hello

I have a personal plan, but when I want to generate a big pdf, after a short period I get the following message: anvil.server.TimeoutError: Server code took too long
According to your last announcement there would be no more limits for background tasks

Thanks for your help

Hi @francois.rivier and welcome!

That error normally comes when you make an ordinary server call that takes too long to run.

Background tasks are something else. The docs on those are at:

Thanks for you answer, is it a solution to solve the problem ?

The error suggests that you haven’t used a background task, but I can’t see your code, so I can’t be certain.

I use the documentation example and adapt it a little bit:

client side:
def btx_download_pdf_click(self, **event_args):
“”“This method is called when the button is clicked”“”
media_object = anvil.server.call(‘create_payment_pdf’, groups=self.groups, owner=self.pharmacy, pdf_selection=self.selection)
anvil.media.download(media_object)

server side:
@anvil.server.callable
def create_payment_pdf(owner:dict=None, groups:dict=None, pdf_selection:dict=None ):
media_object = anvil.pdf.render_form(‘Pharmacy.frmPayment’, groups=groups, pharmacy=owner, pdf=True, pdf_selection=pdf_selection)
return media_object

My form is complex …

As I suspected, there is no background task in that code. You need to read and follow the docs I sent you.

1 Like

Unfortunately, really unfortunately, generating PDF has the 30 second limit even with dedicated plans, even in background tasks.

The problem is that the PDF generation process is a resource hog and is killed after 30 seconds, regardless of your plan.

The solution is to get your background task to gather all the required data, then start the PDF generation passing all the data already gathered to the form, so the time required for the PDF generation is as short as possible.

You can try to search for PDF timeout in the forum to see other posts addressing the same problem.

3 Likes

Thanks stefano and owen for these quick answers, it help a lot