> -----Original Message----- > From: [EMAIL PROTECTED] [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Sent: Tuesday, April 12, 2005 11:04 PM > To: CF-Talk > Subject: pausing a script > > Is there a way of pausing a script in CF MX 6? > > I want to send out 200 emails, wait 60 seconds before executing another > cfmail batch of 200. I have got the following code after the cfmail tag > both of which are nested in an index loop which has a value from 1 to 12. > > <cfset sec = Second(Now())> > <cfset secs = 0> > <cfset TimeSpan = 60> > <cfloop condition="secs LT TimeSpan"> > <cfif sec IS NOT Second(Now())> > <cfset sec = Second(Now())> > <cfset secs = secs + 1> > </cfif> > </cfloop>
You can do this, but it's not very efficient (since you're keeping that thread active and consuming resources for the whole of the sleep time rather than allowing it to go and get other work done). Instead you might consider setting up a task to do this - you can set the tasks programmatically so something like this like this can happen: Launch the process (either through a separate scheduled task or manually). Create (programmatically using <CFSCHEDULE>) a task that runs every minute which calls a mail sender page. The mail sender page: 1) Checks the working flag (described below) to see if it's free to run. If so it checks to see if there's any mail to send; if not it exits immediately. 2) If there's mail to send it sets a "working" flag to true someplace (in a database, in the application scope, etc) and sends 200 messages then sets the working flag to "false". If there's no more mail to send it deletes the scheduled task. In the case of any errors I would log the problem and set the working flag to "false". You can improve things of course but this prevents multiple threads from sending mail at the same time, implements your delay and only uses resources when running. Furthermore since each batch of 200 is running in a separate process one iteration can bomb for some reason and the others will still run meaning that most of your mail will get out regardless. I've used this kind of setup very successfully for delayed log-file batch processing. Jim Davis ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Find out how CFTicket can increase your company's customer support efficiency by 100% http://www.houseoffusion.com/banners/view.cfm?bannerid=49 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:202523 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

