增加CFML中的线程的请求超时 [英] Increase request timeout for a thread in CFML

查看:89
本文介绍了增加CFML中的线程的请求超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web应用程序,在Windows / IIS服务器上使用ColdFusion 8批量生成数百个PDF。

I have a web application that is generating hundreds of PDFs in batch, using ColdFusion 8 on a Windows/IIS server.

这个进程在我的开发上运行良好,分段服务器,但当然客户端是便宜的,只是支付共享主机,这不是我的dev / staging框一样快。因此,PDF生成线程超时。

The process runs fine on my development and staging servers, but of course the client is cheap and is only paying for shared hosting, which isn't as fast as my dev/staging boxes. As a result, PDF generation threads are timing out.

流程如下:


  1. 运行页面以生成PDF。

  2. 运行查询以确定需要生成哪些PDF,并且每个PDF的应用程序范围的UDF调用都会触发循环

  3. UDF查找给定项目的信息,然后为PDF生成工作创建一个线程,防止生成速度减慢页面。
  4. 该线程只是使用CFDocument创建一个PDF并将其保存到磁盘,然后终止。

  1. Page is run to generate PDFs.
  2. A query is run to determine which PDFs need to be generated, and a loop fires off an application-scoped UDF call for each PDF that will need to be generated.
  3. That UDF looks up information for the given item, and then creates a thread for the PDF generation to work in, preventing generation from slowing down the page.
  4. The thread simply uses CFDocument to create a PDF and save it to disk, then terminates.

线程不重新加入,没有什么正在等待他们完成。使UDF调用的页面在几毫秒内完成;

Threads do not re-join, and nothing is waiting for any of them to finish. The page that makes the UDF calls finishes in a few milliseconds; it's the threads themselves that are timing out.

以下是UDF(和线程创建)的代码:

Here is the code for the UDF (and thread creation):

<cffunction name="genTearSheet" output="false" returntype="void">
    <cfargument name="partId" type="numeric" required="true"/>
    <!--- saveLocation can be a relative or absolute path --->
    <cfargument name="saveLocation" type="string" required="true"/>
    <cfargument name="overwrite" type="boolean" required="false" default="true" />
    <cfset var local = structNew() />

    <!--- fix save location if we need to --->
    <cfif left(arguments.saveLocation, 1) eq "/">
        <cfset arguments.saveLocation = expandPath(arguments.saveLocation) />
    </cfif>

    <!--- get part info --->
    <cfif structKeyExists(application, "partGateway")>
        <cfset local.part = application.partGateway
        .getByAttributesQuery(partId: arguments.partId)/>
    <cfelse>
        <cfset local.part = createObject("component","com.admin.partGateway")
        .init(application.dsn).getByAttributesQuery(partId: arguments.partId)/>
    </cfif>

    <!--- define file name to be saved --->
    <cfif right(arguments.saveLocation, 4) neq ".pdf">
        <cfif right(arguments.saveLocation, 1) neq "/">
            <cfset arguments.saveLocation = arguments.saveLocation & "/" />
        </cfif>
        <cfset arguments.saveLocation = arguments.saveLocation & 
        "ts_#application.udf.sanitizePartNum(local.part.PartNum)#.pdf"/>
    </cfif>

    <!--- generate the new PDF in a thread so that page processing can continue --->
    <cfthread name="thread-genTearSheet-partid-#arguments.partId#" action="run" 
    filename="#arguments.saveLocation#" part="#local.part#" 
    overwrite="#arguments.overwrite#">
        <cfsetting requestTimeOut=240 />
        <cftry>
        <cfoutput>
        <cfdocument format="PDF" marginbottom="0.75" 
        filename="#attributes.fileName#" overwrite="#attributes.overwrite#">
            <cfdocumentitem type="footer">
                <center>
                <font face="Tahoma" color="black" size="7pt">
                pdf footer text here
                </font>
                </center>
            </cfdocumentitem>
            pdf body here
        </cfdocument>
        </cfoutput>
        <cfcatch>
        <cfset application.udf.errorEmail(application.errorEmail,
        "Error in threaded PDF save", cfcatch)/>
        </cfcatch>
        </cftry>
    </cfthread>
</cffunction>

如您所见,我已尝试添加< cfsetting requestTimeout = 240 /> 到线程的顶部,尝试使它更长寿命...没有骰子。当我看到 CFThread标记具有超时参数时,我也感到兴奋。 ,但后来意识到它只适用于加入线程(action = join)。

As you can see, I've tried adding a <cfsetting requestTimeout=240 /> to the top of the thread to try and make it live longer... no dice. I also got a little excited when I saw that the CFThread tag has a timeout parameter, but then realized it only applies when joining threads (action=join).

更改ColdFusion Administrator中的默认超时不是一个选项,因为这是一个共享主机。

Changing the default timeout in ColdFusion Administrator is not an option, as this is a shared host.

如果任何人对如何使这些线程活得更长时间有任何想法,我非常感谢他们。

If anyone has any ideas on how to make these threads live longer, I would really appreciate them.

推荐答案

虽然这不直接回答我增加线程超时的原始问题,我已经能够通过改进PDF生成时间使该进程工作(防止超时)。

While this doesn't directly answer my original question of increasing the timeout of a thread, I have been able to make the process work (prevent timeouts) by improving PDF generation time.

根据 livedocs ,ColdFusion 8在 CFDocument 标签中添加了一个 localUrl 属性,

According to the livedocs, ColdFusion 8 added a localUrl attribute to the CFDocument tag that indicates that image files are located on the same physical machine, and should be included as local files instead of making an HTTP request for them.

更改我的 CFDocument

Changing my CFDocument code to the following has made the process run fast enough that the threads don't time out.

<cfdocument format="PDF" marginbottom="0.75" 
filename="#attributes.fileName#" overwrite="#attributes.overwrite#" localUrl="yes">
    <cfdocumentitem type="footer">
        <center>
        <font face="Tahoma" color="black" size="7pt">
            pdf footer text here
        </font>
        </center>
    </cfdocumentitem>
    pdf body here
    <img src="images/foo/bar.gif"/>
</cfdocument>

这篇关于增加CFML中的线程的请求超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆