I found a way to see the error messages, and I think I have solved my
problem!

 

For reference, there's some great info on Ben Nadel's blog:
http://www.bennadel.com/blog/743-Learning-ColdFusion-8-CFThread-Part-I-Data-
Exchange.htm 

 

Here's what you do:

 

<cfthread action="run" name="myThread">

     Your Thread Code goes here

</cfthread>

<cfthread action="join" name="myThread"/>

<cfdump var="# myThread#" /><cfabort>

 

So, you join the thread and that will cause the code to wait for the thread
to finish. Then, you can cfdump the name of the thread and see any output it
generated including error messages. The <cfabort> is in there because this
was running in a CFC, and otherwise, I would never see the output. 

 

My problem was that things running in a cfthread are more sensitive to scope
issues. Here's what I had:

 

<cfset personalMessage = "This is personalized for you">

<cfsavecontent variable="eMailBody">

    <cfinclude template="pathToTemplate">

</cfsavecontent>

 

The template I was including expected a value for personalMessage. As soon
as I explicitly scoped personalMessage like this
"variables.personalMessage", the error went away. 

 

What's weird is that even though CF didn't know personalMessage was defined
it still found it! I defined a <cfparam> in the template so the variable
would always be defined. This stopped the error, but even before I
explicitly scooped the variable, CF still put the right information into the
template.

 

I've been trying to pay attention to scoping variables - I guess this is
another reason to do it right!

 

Thanks again everybody for all your help!

 

   Clarke

 

From: ad...@acfug.org [mailto:ad...@acfug.org] On Behalf Of Clarke Bishop
Sent: Thursday, May 28, 2009 3:22 PM
To: discussion@acfug.org
Subject: RE: [ACFUG Discuss] Sending large numbers of eMail via ColdFusion

 

Thanks Charlie - Your idea helped me learn more about what is going on.

 

What I'm trying to do inside of my <cfthread> is have a loop that for each
eMail address:

.         Creates a personalized eMail 

.         Sends the message with <cfmail>

.         Waits 1000 ms

 

Using <cflog>, I know the thread is starting, but apparently, I am getting
some errors that cause the thread to terminate.

 

Before, I was using <cfsavecontent> and <cfinclude> to assemble my
personalized eMail message. The message has a header, a body, and a footer
and I have a <cfinclude> for each section.

 

But, <cfthread> and <cfsavecontent> don't seem to want to play nice
together. I know cfthread can't send output to the page, but that's not what
I'm trying to do. I just want to create my personalized message, save it in
a variable, and send it out via <cfmail>.

 

I may also have some path problems with the cfincludes, but even when I
comment all that out, everything seems to fail right after the
<cfsavecontent>.

 

Has anyone experienced these issues? Do you have any suggestions for me?
And, one more question. Is there a way to see error messages that get thrown
inside of  a thread?

 

This is ending up being trickier than I thought. Oh well!

 

   Clarke

 

From: ad...@acfug.org [mailto:ad...@acfug.org] On Behalf Of Charlie Arehart
Sent: Thursday, May 28, 2009 9:02 AM
To: discussion@acfug.org
Subject: RE: [ACFUG Discuss] Sending large numbers of eMail via ColdFusion

 

Clarke, I wouldn't rely on the server monitor as proof of whether the thread
runs. For one thing, you have to have "start monitoring" enabled, which
isn't on by default. Just thought I'd clarify that if it might be the only
reason you don't see them. Even then, the threads could run very fast.

 

I'd recommend instead you go old school, and throw a CFLOG into the thread
code (and outside the thread code) to write to a file that you can look at
to confirm if it's ever written to.

 

/charlie

 

From: ad...@acfug.org [mailto:ad...@acfug.org] On Behalf Of Clarke Bishop
Sent: Wednesday, May 27, 2009 5:52 PM
To: discussion@acfug.org
Subject: RE: [ACFUG Discuss] Sending large numbers of eMail via ColdFusion

 

Thanks for the ideas Troy, Dawn, and Doug!

 

I decided to try out cfthread as my code was already much like what Troy
suggested.

 

Here's what I have now:

 

<cfthread name="sendPR" action="run">

    <cfloop query="qEmails">

        <cfif qEmails.personalized EQ True>

            <cfset personalMessage = qEmails.message>

        <cfelse>

            <cfset personalMessage = "">

        </cfif> 

 

        <cfset sendMail(qEmails.eMail, subjectMsg, personalMessage,
Template)>

        <cfset sleep(1000)>

    </cfloop>

</cfthread>

 

The only thing is the thread doesn't seem to run. The above code is inside a
CFC function, and the sendMail() call goes to another method in the same
CFC? I saw an example on the web where someone did this, so I think it's OK.

 

Any ideas what I might be doing wrong? Also, are there good ways to
trouble-shoot with cfthread. The code runs correctly when I comment out the
cfthread tags. But when they are in there, nothing seems to happen. No
thread ever shows up in the Server Monitor.

 

Thanks for any pointers!


------------------------------------------------------------- 
To unsubscribe from this list, manage your profile @ 
http://www.acfug.org?fa=login.edituserform 

For more info, see http://www.acfug.org/mailinglists 
Archive @ http://www.mail-archive.com/discussion%40acfug.org/ 
List hosted by FusionLink <http://www.fusionlink.com>  
------------------------------------------------------------- 


------------------------------------------------------------- 
To unsubscribe from this list, manage your profile @ 
http://www.acfug.org?fa=login.edituserform 

For more info, see http://www.acfug.org/mailinglists 
Archive @ http://www.mail-archive.com/discussion%40acfug.org/ 
List hosted by FusionLink <http://www.fusionlink.com>  
------------------------------------------------------------- 




-------------------------------------------------------------
To unsubscribe from this list, manage your profile @ 
http://www.acfug.org?fa=login.edituserform

For more info, see http://www.acfug.org/mailinglists
Archive @ http://www.mail-archive.com/discussion%40acfug.org/
List hosted by http://www.fusionlink.com
-------------------------------------------------------------

Reply via email to