David Thielen
David Thielen

Reputation: 32874

If a REST request can take 10 minutes

I'm about to implement a REST server (in ASP.NET although I think that's irrelevant here). where what I want to do is the request is made and it returns the result. However, this result is an .XLSX file that could be a million rows.

If I'm generating a million row spreadsheet, it's going to take about 10 minutes. An http request will time out. So what's the best way to handle this delay in the result.

Second, what's the best way to return a very large file as the REST result?

Update: The most common use case is the REST server is an Azure cloud service web worker (basically IIS on Azure). The client is a PHP web app running on a different server in a different location. The PHP web app needs to send up a report template (generally 25K) and the data which can be a connection string to a SQL database, or... could be a 500M XML file. So that is the request, an XML file containing the template and datasource(s).

The response if a file - PDF, DOCX, XLSX, PPTX, or HTML. That can be a BLOB inside an XML file or it can be the file itself. In the case of an error then it must return XML with the error information. The big issue is it can take 10 minutes to generate this file if everything goes right. When it's a 1 million row spreadsheet, it takes time to pull down all that data and populate the created XLSX file. Second issue, this is then a really large file.

So even if everything is perfect, there's a big delay and a large response.

Upvotes: 0

Views: 1142

Answers (2)

hanshenrik
hanshenrik

Reputation: 21463

interesting question, i sure hope you have a stable connection, anyway, at the client side, in this case, php, set the timeouts to very high values. in php set_time_limit(3600*10); curl_setopt($curlh,CURLOPT_TIMEOUT,3600*10);

Upvotes: 0

rtf_leg
rtf_leg

Reputation: 1819

I see two options:

  • Write file to response stream during its generation (from client side this looks like downloading large file);
  • Start file generation task on server side and return task id immediatly. Add API methods, that allows retreive task status, cancel it or get results (if task completed).

Upvotes: 1

Related Questions