tags:

views:

197

answers:

5

I'm writing a database load script in ColdFusion. It loads about 150,000 records across a dozen tables. I am running the script through a web browser request. Is there any way to kill the process once I've requested the page? I can stop the page in the browser, but the database inserts continue on the backend until the script has completed, which makes the debugging process very slow since I have to run the entire script each time. Is there anything I can do through the Java backend?

The environment I'm in is ColdFusion 8 running through IIS. I have the performance monitoring disabled, but I'd like to be able to mimic the ability to kill jobs as in the performance monitor.

+1  A: 

In the loop through the 150,000 records can you just stop it at whatever number you think is appropriate. Set a counter variable and whenever it gets there in the loop just <cfabort> or <cfbreak> .

Jason
+3  A: 

I'd tried to make something like Unix pid-file: your script should periodically (maybe each 10/100/1000 iterations) check the availability of some file in the filesystem and stop executing if it contains certain value, or maybe if exists or not at all.

Of course, this can be a field in the database, variable in application scope (with appropriate locking strategy), or anything you find suitable.

You also need second script which will be changing the state of your "pid-object". This can be as simple as another .cfm you can pull with the browser.

Sergii
A very simple solution. The following code did it for me:` <cfif fileExists("#getDirectoryFromPath(getCurrentTemplatePath())#\halt.txt")> <cfset fileDelete("#getDirectoryFromPath(getCurrentTemplatePath())#\halt.txt")> <cfset logMsg("ALERT: database sync aborting by request at #formatDateOutput(now())#")> <cfabort> </cfif>`
stomcavage
A: 

with some products like fusionreactor, you can kill the underlying java thread, but if the database actually has control of the request, you can't make it stop (on the database). You have to wait until the database returns control of the thread.

Ryan Guill
A: 

You will probably want to run the process using cfthread.

Start your process like...

<cfthread name="myThread" action="run"> 
    ...Your loop to insert into database....
</cfthread>

Then you can kill the thread by using...

<cfthread action="terminate" name="myThread"/>
Eddie
A: 

If you have management software such as FusionReactor installed, you can use that to halt running scripts.

MightyE