LoginSignup
3
1

More than 5 years have passed since last update.

【ColdFusion】時間のかかるダウンロード処理をタイムアウトさせる

Posted at

ファイルを生成してダウンロードさせる処理でタイムアウト時間を設けたい

Excelファイルを生成する処理なんかは何分も返ってこないことがありますね。
そこで1分経ったら諦めてもらう処理です。

<!--- ダウンロードファイル作成 --->
<CFTHREAD action="run" name="making_file">
    <!--- makingFile()は成功時ファイル名を返します --->
    <CFSET variables.sOutputFileNm = makingFile()>
</CFTHREAD>

<!--- 終わるまで最大1分待つ --->
<CFTHREAD action="join" name="making_file" timeout="60000" />

<CFIF isDefined("sOutputFileNm") && sOutputFileNm neq "">
    <!--- ファイルが出来ていたらダウンロード --->
    <CFSET downloadFile(sOutputFileNm)>
<CFELSE>
    <CFIF findNoCase("RUNNING", CFTHREAD.making_file.status)>
        <!--- 終わってなければ中断 --->
        <CFTHREAD action="terminate" name="making_file" />
        <CFSET errmes = "ダウンロード処理でタイムアウトしました。">
    <CFELSE>
        <!--- 終わってるのにファイル名が返ってないのは何かのエラー --->
        <CFSET errmes = "ダウンロードに失敗しました。">
    </CFIF>
</CFIF>

CFTHREAD内の変数は、明示的にvariablesスコープを付けないとCFTHREAD外からはアクセスできませんので注意してください。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1