Working around Cloudflare 100 second timeout?
-
DavidLee82
- Posts: 24
- Joined: Wed Jul 03, 2024 12:52 am
Working around Cloudflare 100 second timeout?
Hi all,
This has been bothering me for ages. Occasionally we would have reports that takes ages (>2 minutes) to generate. On our local testing the report comes out okay after the long processing. However on sending to Production the report will more than often end up showing a Cloudflare 524 error instead of completing.
I am told that Cloudflare limits HTTP requests to 100 seconds. The reports takes 3-4 minutes to execute due to the sheer size of the dataset.
Does Stimulsoft have a method to work around the limit? For example, fire the job, close the connection and display a wait screen, then wait for the server to call back with a completed report?
This has been bothering me for ages. Occasionally we would have reports that takes ages (>2 minutes) to generate. On our local testing the report comes out okay after the long processing. However on sending to Production the report will more than often end up showing a Cloudflare 524 error instead of completing.
I am told that Cloudflare limits HTTP requests to 100 seconds. The reports takes 3-4 minutes to execute due to the sheer size of the dataset.
Does Stimulsoft have a method to work around the limit? For example, fire the job, close the connection and display a wait screen, then wait for the server to call back with a completed report?
-
Lech Kulikowski
- Posts: 7842
- Joined: Tue Mar 20, 2018 5:34 am
Re: Working around Cloudflare 100 second timeout?
Hello,
You can offload the generation of such heavy reports to the server side.
- Your own lightweight endpoint starts a background task: it loads the .mrt, sets the data sources/variables, and calls report.Render() - this happens outside the request thread, so nothing is left hanging behind Cloudflare while rendering is in progress.
- Once complete, report.SaveDocument() ьуерщв is called, or the report is exported - this saves the actual rendered result, not the template.
- The frontend polls a small status endpoint until the task status becomes "ready".
- When the result is ready, instead of loading the original report (which would trigger a full re-render), you pass the already rendered document to the viewer - report.LoadDocument(). Since it is already rendered, this call returns quickly - the open connection is no longer left hanging.
Thank you.
You can offload the generation of such heavy reports to the server side.
- Your own lightweight endpoint starts a background task: it loads the .mrt, sets the data sources/variables, and calls report.Render() - this happens outside the request thread, so nothing is left hanging behind Cloudflare while rendering is in progress.
- Once complete, report.SaveDocument() ьуерщв is called, or the report is exported - this saves the actual rendered result, not the template.
- The frontend polls a small status endpoint until the task status becomes "ready".
- When the result is ready, instead of loading the original report (which would trigger a full re-render), you pass the already rendered document to the viewer - report.LoadDocument(). Since it is already rendered, this call returns quickly - the open connection is no longer left hanging.
Thank you.
-
DavidLee82
- Posts: 24
- Joined: Wed Jul 03, 2024 12:52 am
Re: Working around Cloudflare 100 second timeout?
Noted with thanks.
-
Lech Kulikowski
- Posts: 7842
- Joined: Tue Mar 20, 2018 5:34 am
Re: Working around Cloudflare 100 second timeout?
Hello,
You are welcome.
You are welcome.
-
DavidLee82
- Posts: 24
- Joined: Wed Jul 03, 2024 12:52 am
Re: Working around Cloudflare 100 second timeout?
Ok, so I'm starting to work on this. However I'm having one hiccup.
I am trying to pass my Variables over to the background thread. Due to how threads in EntityFramework works, I can't pass variables directly to the thread; to pass data to the thread I am reusing a flatfile format I devised for other purposes.
Here's the issue. I am now having trouble sending my variables over. I used the ToJson() method for StiVariablesCollection to serialize the data which seems to be working as intended. However I am unable to deserialize the data back to a useable object. I tried using JsonSerializer.Deserialize<StiVariablesCollection> the Collection itself looks okay but the content within the collection didn't deserialize as it should. I was told by AI about this StiJsonToObject method which will make things right, however that doesn't seem to exist? However AI seems adamant and consistent that StiJsonToObject is a thing so I'm really confused since hallucinations don't persist like that.
Edit: Nevermind. Worked out a solution. I have to use JsonConverter on both sides, not JsonSerializer. Once I have that sorted out everything's working.
I am trying to pass my Variables over to the background thread. Due to how threads in EntityFramework works, I can't pass variables directly to the thread; to pass data to the thread I am reusing a flatfile format I devised for other purposes.
Here's the issue. I am now having trouble sending my variables over. I used the ToJson() method for StiVariablesCollection to serialize the data which seems to be working as intended. However I am unable to deserialize the data back to a useable object. I tried using JsonSerializer.Deserialize<StiVariablesCollection> the Collection itself looks okay but the content within the collection didn't deserialize as it should. I was told by AI about this StiJsonToObject method which will make things right, however that doesn't seem to exist? However AI seems adamant and consistent that StiJsonToObject is a thing so I'm really confused since hallucinations don't persist like that.
Edit: Nevermind. Worked out a solution. I have to use JsonConverter on both sides, not JsonSerializer. Once I have that sorted out everything's working.
-
Lech Kulikowski
- Posts: 7842
- Joined: Tue Mar 20, 2018 5:34 am
Re: Working around Cloudflare 100 second timeout?
Hello,
Thank you for the information.
Thank you for the information.
-
DavidLee82
- Posts: 24
- Joined: Wed Jul 03, 2024 12:52 am
Re: Working around Cloudflare 100 second timeout?
Hi,
Just wondering, does the StiReport object fire an event whenever the ProgressOfRendering counter is incremented? If yes, which event should I listen for? I just thought I want to experiment with providing feedback of the render progress to the user as well. Currently we've succeeded in getting the report to render in background and then redirecting the user when it's done, but we'd like to provide more feedback to the user outside of a stopwatch if possible.
Just wondering, does the StiReport object fire an event whenever the ProgressOfRendering counter is incremented? If yes, which event should I listen for? I just thought I want to experiment with providing feedback of the render progress to the user as well. Currently we've succeeded in getting the report to render in background and then redirecting the user when it's done, but we'd like to provide more feedback to the user outside of a stopwatch if possible.