Bypassing CloudFlare's time-out of 100 seconds

后端 未结 2 2113
心在旅途
心在旅途 2021-02-10 03:43

I am attempting to AJAX-ify my reports in order to bypass the 100 seconds time-out that CloudFlare imposes on requests that run through its site.

See Is it possible to i

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-10 04:08

    In case anyone else has the same problem, I am posting how I finally got this working. I gave up trying to use AJAX to run the report, but instead ran the report via a Thread, but used AJAX to "poll" to check if the report had been created. What I did was basically as follows.

    Note that I stripped a lot out of my code, e.g. security routines and error checking routines, just to give the basic framework.

    I created a java class called ThreadMyReport

    public class ThreadMyReport implements Runnable {
    
        String fileID = "";
        Date dateOfReport = null;
    
        public ThreadMyReport(Date dateOfReport) {
            this.fileID= "MyReport_" + UUID.randomUUID();
            this.dateOfReport = dateOfReport;
        }
    
        public void run() {
            int a = ReportMyReport.loadAndSaveMyReport(dateOfReport, fileID);
        }
    
    
        public String getFileID() {
            return fileID;
        }
    }
    

    All my original code to generate the report is found in ReportMyReport.loadAndSaveMyReport. When the report is finished, then it saves a file with fileName fileID on the server.

    I then started a thread going to run the report

        ThreadMyReport a  = new ThreadMyReport(theDate);
        Thread theThread=new Thread(a);
        theThread.start();
        fileID=a.getFileID();
    

    I then added a javascript routine to check via AJAX every second whether the file had been created, and if it had been created then to display the report.

    
    

    The AJAX code looks like this:

         <%
        String result="";
    
        String generatedReport=(request.getParameter("generatedReport"));
    
        if(!"".equals(generatedReport)) {
            String fileName2="My directory/"+generatedReport+".xlsm"; 
            java.io.File f = new java.io.File(fileName2);
            if(f.exists()) { 
                result="produced";
            }
        }
    }
    
    %>
    <%=result%>
    

提交回复
热议问题