Search
Coldfusion Web Server-Client to throttle down or pace processing (pseudo-cron)




(1 votes, average: 4 out of 5)Today I wrote a small piece of code that I have wanted to use for some time now. I would rather have had found and ripped this code off of someone else online using a Google search, but either I wasn’t entering in the right phrases or no one has made their code easy enough to find.
Enough with the suspense already. I needed to run a bunch of SQL updates, but I didn’t want to tie up the system, so I was looking to, for lack of a better description, “pace” the batch processing. When looking at it, its admittedly simple, but I had a mental block trying to do this exclusively in coldfusion. This solution is a mix of CF and plain old web server plus web client.
Sure, I could have used cron, but this was a small job, and not worth the hassle for me. I’m sure someone has done similar before, but for those who are endlessly searching for this, like I had been, here you go. Also, I imagine many will have alternative methods or suggestions on improving this, please share with us and comment.
<cfparam name="start" default="1"> <!--- start with 1 --->
<cfparam name="next" default="0"> <!--- start with next as zero --->
<cfparam name="wait" default="60"> <!--- change the duration of the page refresh --->
<cfset start = next + 1> <!--- the counter --->
<cfif start eq 3> Done. <cfabort></cfif> <!--- puts an end to the refreshing --->
<html>
<head>
<title>Batch process</title>
<!--- this will use the parameters above and/or from the URL you enter to change the refreshing
in this case, I named the file "pace-batch-process.cfm" --->
<cfoutput>
<meta HTTP-EQUIV="refresh" content="#wait#;URL=http://www.yourdomain.com/pace-batch-process.cfm?next=#start#&wait=#wait#">
</cfoutput>
</head>
<body>
<cfif start eq 1>
Run the first thing
</cfif>
<cfelseif start eq 2>
Do the second thing
<cfelseif start eq 3>
Run the third thing
<cfelse>
Do nothing
</cfif>
</body>
</html>
Again, I imagine many will have suggestions on this, both positive and negative, please share and comment.
Recent Posts
Blogroll
Categories
Up on the Roof…uh is proudly powered by WordPress Designed by Ebay Business
Posts
October 6 2007
Thats a really simple approach. I have a similar chunk of code I wrote in php.
Instead of hardcoding the values of: how much todo and where to start/finish. I have stored those values in a db table.
I also stored the “work to be done” in a seperate table which had a flag to say whether or not that row is completed.
Then the core of my cron-like-worker says: start wherever you didn’t finish last, and go upto MAX row skipping anything DONE. If things didn’t finish up last time, it grabs the first thing not finished and starts from there … and skips over finished stuff back to where the bulk of the work is.
Since I use a master “task table” (holds task_id, description, number of tasks completed in last run, number of tasks todo per run, last runtime) and a “task todo table” (holds the stuff that needs to be done). I can have many little tasks running every one and then.
I normally cron the master file that runs all this. But, in essence I have small php-driven cron jobs which my system admin doesn’t have to worry about. And the code is written in such a way as to never do more than XX rows at a time, per task.