开发者

How can I force ColdFusion to stop rendering a page until a process invoked with <cfexecute> completes?

开发者 https://www.devze.com 2023-03-02 08:09 出处:网络
I\'m working on a script that creates a MySQL dump via <cfexecute> and then FTPs the SQL script开发者_Python百科 to another server. I\'ve resorted to checking once per second to see if the files

I'm working on a script that creates a MySQL dump via <cfexecute> and then FTPs the SQL script开发者_Python百科 to another server. I've resorted to checking once per second to see if the filesize has changed, and if it has not changed within the past five seconds I assume it has completed.

This is fine for the current application, but eventually I would like to be able to import the SQL script on the second server and provide some sort of notification that it has completed.

Is there some way to track the status of a running process?

If not, is there a way to accomplish a full DB export and import via ColdFusion alone?


Actually you may not realize it, but when you call <cfexecute> without passing a timeout attribute it defaults to '0' timeout. And if you read the docs on <cfexecute> you'd see:

If the value is 0:

ColdFusion starts a process and returns immediately. ColdFusion may

return control to the calling page before any program output displays. To ensure that program output displays, set the value to 2 or higher.

So I would suggest passing a higher value for timeout which will cause ColdFusion to wait for mysqldump to complete before moving on.

Reference


Check out Event Gateways[1] for one way to deal with asynchronous operations. There's a Directory Watcher gateway that comes with CF as an example.[2]

Barring that, create some sort of batch processing facility using CF Scheduled Tasks. Add the job to a database table and have a scheduled task periodically pull jobs out of the table and execute them, reporting on the result. A second scheduled task can detect that the first completed and carry out the next step of the process.

[1] http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec214e3-7fa7.html [2] http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-77f7.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号