限制被调用 CFC 的执行时间
Limiting Execution Time for a called CFC
我们有一个 ColdFusion 编辑器,可以检查 MX 记录以软验证电子邮件地址。我们偶尔会从 DNS 服务器收到较长的响应,因此需要限制我们在放弃之前等待响应的时间。
调用的组件执行实际查找。下面复制的代码是幼虫验证脚本的一部分。
我想做的是将等待查找组件的时间限制为运行,然后在超过该时间时处理错误。这段代码对我来说似乎是正确的,但它刚好超过了超时时间(我在组件中有一个 "sleep" 来模拟缓慢的响应。)
try {
requesttimeout="10";
MyNewArray[1] = right(MyEmail, RightChars);
mycnt = new common.functions.mxLookup(MyNewArray);
Caller.EmailReturnCode = iif(mycnt gt 0,'"0"','"2"');
}
catch ("coldfusion.runtime.RequestTimedOutException" a) {
Caller.EmailReturnCode = "2";
}
catch (any e) {
Caller.EmailReturnCode = "2";
}
thread action="run" name="doLookup" {
variables.mycnt = new common.functions.mxLookup(MyNewArray);
}
thread action="join" name="doLookup" timeout="20000";
if(doLookup.Status is "RUNNING"){
thread action="terminate" name="doLookup";
throw("MX Lookup of #MyEmail# timed out", "toException", "MX Lookup exceeded allowed time of 20 seconds at #timeFormat(now(),'HH:mm:sss')#");
}
Caller.EmailReturnCode = iif(mycnt gt 0,'"0"','"2"');
感谢亚历克斯
这个解决方案非常有效。
我们有一个 ColdFusion 编辑器,可以检查 MX 记录以软验证电子邮件地址。我们偶尔会从 DNS 服务器收到较长的响应,因此需要限制我们在放弃之前等待响应的时间。
调用的组件执行实际查找。下面复制的代码是幼虫验证脚本的一部分。
我想做的是将等待查找组件的时间限制为运行,然后在超过该时间时处理错误。这段代码对我来说似乎是正确的,但它刚好超过了超时时间(我在组件中有一个 "sleep" 来模拟缓慢的响应。)
try {
requesttimeout="10";
MyNewArray[1] = right(MyEmail, RightChars);
mycnt = new common.functions.mxLookup(MyNewArray);
Caller.EmailReturnCode = iif(mycnt gt 0,'"0"','"2"');
}
catch ("coldfusion.runtime.RequestTimedOutException" a) {
Caller.EmailReturnCode = "2";
}
catch (any e) {
Caller.EmailReturnCode = "2";
}
thread action="run" name="doLookup" {
variables.mycnt = new common.functions.mxLookup(MyNewArray);
}
thread action="join" name="doLookup" timeout="20000";
if(doLookup.Status is "RUNNING"){
thread action="terminate" name="doLookup";
throw("MX Lookup of #MyEmail# timed out", "toException", "MX Lookup exceeded allowed time of 20 seconds at #timeFormat(now(),'HH:mm:sss')#");
}
Caller.EmailReturnCode = iif(mycnt gt 0,'"0"','"2"');
感谢亚历克斯
这个解决方案非常有效。