1

I have an application which sends an AJAX request to execute some server-side code. This code takes approximately 10 minutes to execute and respond with data.

Both the web server and browser timeout well before this operation completes. What is the best way to structure this request to prevent a gateway timeout?

The ajax request responds with a json object. Is this the correct structure for handling this?

Client executes ajax to start server-side processing
|
|___server working to process data (ETA 10 min)
|  |
|  server finishes and writes file with json object
|
Client recursively ajax requests some endpoint to check for completion
|
|___endpoint returns true
   |
   ajax request for server generated JSON file
Query
  • 720
  • 2
  • 7
  • 23
  • 1
    Do you have any example code of what you've attempted to do? Have you looked at something like a Service Bus (e.g. RabbitMQ). – ACOMIT001 Apr 12 '17 at 14:17
  • if you've got 'Gateway timeout' you have to edit server configuration – Alex Slipknot Apr 12 '17 at 14:19
  • @Alex Slipknot I've increased the timeout on the server but the browser then returns a timeout as well. – Query Apr 12 '17 at 14:39
  • For ajax there is setting for timeout: http://stackoverflow.com/questions/5225597/set-timeout-for-ajax-jquery But I think if you saw response in console 502 or 504 - there is missed settings for timeout on server – Alex Slipknot Apr 12 '17 at 14:53
  • I've read that the jquery ajax function by default has a timeout 0 (never), is that not correct? – Query Apr 12 '17 at 16:06

1 Answers1

0

In the end I decided to use websockets. It seems like if it is a very long operation you can either generate a file and check for that file, or make a real-time app with websockets.

Query
  • 720
  • 2
  • 7
  • 23