Mosh,

On 5/31/2011 1:42 PM, Mosh Teitelbaum wrote:
>
> All:
>
> I'm working on a system that will have a large number of timed,
> one-time tasks that need to be executed on a schedule.  I'm trying to
> figure out the best way to accomplish this with cfschedule.  The two
> options I see are as follows:
>
> 1. A single, recurring task that runs every 5 minutes and queries the
> database for any tasks that need to be executed.  The benefit of this
> approach is that there is only a single task to create.  The
> negatives of this approach are (a) potentially querying the database
> when there are no tasks to execute (waste of resources) and (b) risk
> of too many tasks at any given time causing the scheduled execution
> to time out or cause later tasks in the run to be executed so late as
> to be off schedule.

(a) The overhead of running a script that doesn't find anything to run 
should be extremely minimal, so I wouldn't even factor this in as a 
waste of resources.

(b) You can always limit the number of tasks you're going to execute in 
one pass--that way you'll never run too many requests in a single batch.

Also, depending on your needs, if you have some requests that you know 
are long running, you could build into your scheduling queue when a 
valid window for that task is to run.

So, if you know a task might take 5 minutes to run (because it does a 
ton of warehousing, etc) you could make sure those type of events only 
run during non-peak hours.

> 2. Create a new cfschedule task for each task that needs to be run.
> The benefits of this approach are that it solves all of the negatives
> of the other approach.  The negatives are that it would necessitate
> the creation of a very large number of cfschedule events and I don't
> know if this could negatively affect the scheduler or CF
> performance.
>
> Either approach would include code to do cleanup (e.g., delete the
> task from the CF scheduler after it has been executed, etc.).
>
> Any thoughts as to which approach (or a different one altogether) is
> better?

I've always preferred having a single background task to manage a queue, 
rather than trying to schedule everything via <cfschedule /> and clean 
up afterwards.

For one, it's much easier to catch errors. It also gives you a single 
point of entry/failure.

You can easily build reports on your executed tasks--because you're 
already storing that stuff in the database. If it's important enough, 
you can find out how long each task is taking to execute, find which 
generated errors, re-queue events, etc.

You can also really easily just fire off stuff in queue manually.

-Dan

-- 
Dan G. Switzer, II
dswit...@pengoworks.com
http://blog.pengoworks.com/

█▀▀▀▀▀█ ▄▀ ▄█▄▄█  █▀▀▀▀▀█
█ ███ █ ▀███▀ █▀  █ ███ █
█ ▀▀▀ █ █▄ ▄  ▀██ █ ▀▀▀ █
▀▀▀▀▀▀▀ █▄▀ █ █ ▀ ▀▀▀▀▀▀▀
█▀▄█▄▄▀▀  █▄▀██ █▄█▀▀ ▀▀▄
  ▄▀█▄▀▀▀▄▀▀▄▄▄█ ▄█▄▀▀  ▀▀
▀▀▄▄▀▀▀▀█▄▄▀▀█ ▀▀██▄ █▄▀█
▀▄ ▄▀ ▀  ▀▀█▄█▄▄▄ █▄▀▄▀▄▀
▀▀ ▀▀ ▀ █▀ ██▄ ▄█▀▀▀███ ▄
█▀▀▀▀▀█ ▀▄█ ▄▀█▀█ ▀ █▄▄▀█
█ ███ █ ▄▀▀ █▀ ▄▀█▀██ ▄▀
█ ▀▀▀ █ ▄ █▄ ▄▄ ▄▄▄ ▀█▀ ▀
▀▀▀▀▀▀▀ ▀▀  ▀▀ ▀▀  ▀   ▀▀

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:345015
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to