Can I stop a ColdFusion request?

I have a Flex application that calls a function that searches for a large collection of documents. Depending on the search condition, the user may want to stop the request from flex.

Id like to not only stop the flex application from the expected request, but also stop the CFC request. Is it possible? What is the best approach for this?

+4
source share
4 answers

To add Ben Doom's answer, I include sample code for the way this can be done. There are several approaches and ways of naming, organizing and calling the code below, but hopefully this is helpful.

At some point during the start of the request, save the process information in a common area and return the identifier to the client. Here is an example of the functions that can be used on a page or remote requests.

<cffunction name="createProcess" output="false"> <cfset var id = createUUID()> <cfset application.processInfo[id] = { progress = 0, kill = false }> <cfreturn id /> </cffunction> 

The client can then check the progress of the request on the survey server or send a request to kill the process

 <cffunction name="getProcessProgress" output="false"> <cfargument name="processID" required="true"> <cfreturn application.processInfo[arguments.processID].progress /> </cffunction> <cffunction name="killProcess" output="false"> <cfargument name="processID" required="true"> <cfset application.processInfo[arguments.processID].kill = true /> </cffunction> 

The actual server process in question can then click on a function, for example, during a cycle, to check whether it should be interrupted and clear any work as necessary.

 <cffunction name="shouldKillProcess" output="false"> <cfargument name="processID" required="true"> <cfreturn application.processInfo[arguments.processID].kill /> </cffunction> 
+2
source

I do not think that there is a direct way to stop the page from being called from the outside. According to the docs, only the thread itself and its parent can interrupt the given thread.

However, you can set a flag for this stream in the general area.

Let's say you call a method that starts some background processing. It generates a unique identifier for the stream and returns it to the caller. The thread looks for a flag in the (for example) area of ​​the application that tells it to stop. It checks every sub-step of the background process. It can interrupt at any time when the flag is reset.

To clear the flag, add an interrupt method that accepts the name of the thread to be interrupted, along with enough protection to make sure that the third party cannot just start killing the threads.

+6
source

If you are using ColdFusion 8, you can use the <cfthread> . You can start the search process on your thread, and then use the remote call to terminate the search flow as needed.

+1
source

You can programmatically complete requests using <cfabort/> or <cfsetting requesttimeout="0"/> - but on the server side of the CF, what I don't think you are asking?

Terminate it remotely ... well, if you have FusionReactor, you might be able to contact him using Flex and abort his request. (You can, of course, try to complete the requests in FusionReactor, but can Flex really ask FR to stop it ... you will need to ask what's on the FR mailing list if there is a way to do this.)


Perhaps an alternative solution is to try archiving the search so that it works on multiple queries, but as much as possible depends on what you are looking for.

0
source

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


All Articles