Server processing

I have a web application that will do some processing with the data provided. Instead of forcing the user to wait for at least a few seconds, maybe up to several minutes under heavy load, I would like to know if there is any way, within coldfusion, to have processing that just happens on the server .

In principle, the data will be transferred to the server, and then the user will be redirected to the main page to allow them to do other things, but may not be able to immediately see the results. Meanwhile, data processing will occur on the server and will be entered into the database upon completion.

Is this possible within the framework of coldfusion, or will I need to study the code that will receive the data and process it as a separate program?

+4
source share
5 answers

ColdFusion 8 introduced the cfthread tag, which can help you.

<cfthread required name="thread name" optional action="run" priority="NORMAL|HIGH|LOW" zero or more application-specific attributes> Thread code </cfthread> 
+6
source

To do this reliably, you can use the database table as a job queue. So you, when the user sends the data that you insert into the database, indicate that there is some work. Then you create a scheduled task in the CF administrator, who will query the script, which receives the next task from the queue and processes the processing described by you. Upon completion, he can update the database, and then you can warn your user about the completion of the task.

Make sense?

+3
source

Another option that may work for you is to use AJAX to send data to the server. This is a pretty easy way to use, since you can use almost the same CF code that you have now, and instead you only need to change the form submit page (and you can even use some unobtrusive javascript methods to make it degrade gracefully, if javascript is not).

Here is an example of using jQuery and BlockUI , which will work unobtrusively, representing any form on your page in a background thread:

 <script> $(function () { $("form").on("submit", function (e) { var f = $(this); e.preventDefault(); $.ajax({ method: f.attr("method"), url: f.attr("action"), data: f.serialize(), beforeSend(jqXHR, settings) { f.blockUI({message: "Loading..."}); }, complete(jqXHR, textStatus) { f.unblockUI(); }, success: function (data, textStatus, jqXHR) { // do something useful with the response }, error: function(jqXHR, textStatus, errorThrown) { // report the error } }); }); }); </script> 
+2
source

You must combine all three of these answers to give you a complete solution.

  • Use CF Thread to β€œstart” work.
  • Add a record to the database to indicate that the process is running.
  • Use Ajax to check the database record to see if the work is completed. when your thread finishes updating the record - Ajax finds work and you will see some message or indicator so that they can go to step 2 or both. Therefore, each of these answers contains the key to a complete solution.

Not sure if this should be an answer or comment (as I am not adding anything new here).

+1
source

The CF event gateway is used for this. The user submits the file via the web form, and the event gateway controls the loading of the directory. Based on the file name, the gateway knows how it should handle the file in the database. Thus, the only real delay that the user encounters is when the file is actually transferred from their machine to the server. However, we do not need to inform the user of any statuses associated with the process, although they could easily see how this can be done if we did.

0
source

Source: https://habr.com/ru/post/1403574/


All Articles