Generate PDF-Report (too slow)

I have a report which takes about 40 sec to generate (there are a lot graphs)

Now I used Brookes tutorial on PDF to generate a pdf and got that error message:

anvil.server.TimeoutError: Server code took too long

What shall I do? (don´t want to seperate the report on several forms).
Cheer Aaron

Background tasks are the usual answer for off-loading long running tasks: Anvil Docs | Background Tasks

That only works if you’re on a paid plan, though. I’m pretty sure that for the free plan background tasks have the same time limit as server functions.

1 Like

Thx - that is a brillant idea (I am on a paid plan).

Background tasks is running,
on client side I want to save the pdf with
anvil.media.download(pdf)

Then I get the error:
AttributeError: ‘LiveObjectProxy’ object has no attribute ‘url’

What can I do to save the pdf?

There is no question in your post and not even enough detail to guess at what it might be.

(I suppose I could guess, but that’s not a great use of anyone’s time).

Please read:

And then have another go.

Here is a link where someone asked a similar question and I pointed them to a clone link with some example code of background tasks working:

Here is another link where I just showed off an easy formatting style to keep track of what is what:

Finally, here is a link to when I discovered background tasks due to someone asking about them, with some of the sharper points of the docs smoothed out for a newcomer to the concept:

This should solve many issues someone might have, if the issue really is background task-related.

Edit: You may also run into a problem ( as detailed in the last link ) where you are trying to return a media object directly to the client from a background task, AFAIK that is still not something you are able to do, and something there are have been many discussions about already, with workarounds, etc.

Thank you Ian,
I will try that.
Aaron

I modified the title of your post to add (too slow) that way when someone else searches the forum for something like:

" PDF too slow "

…this topic will show up.

I hope you don’t mind.

Here are a few things to consider that could help: Exception: PDF generation failed: Components did not load within allowed time - #4 by ianbuywise

1 Like