Friday, March 19, 2010    
Home My Books Blog ColdFusion About Me Back    

Calendar
<< Aug 2006 >>
S M T W T F S
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Search

Categories
 • Acrobat (3) [RSS]
 • Adobe (90) [RSS]
 • AdobeMAX06 (45) [RSS]
 • AdobeMAX07 (59) [RSS]
 • AdobeMAX08 (66) [RSS]
 • AdobeMAX09 (39) [RSS]
 • AdobeMAX10 (1) [RSS]
 • AIR (219) [RSS]
 • Appearances (191) [RSS]
 • Books (72) [RSS]
 • CFEclipse (15) [RSS]
 • ColdFusion (1381) [RSS]
 • Data Services (34) [RSS]
 • Fish Tank (5) [RSS]
 • Flash (197) [RSS]
 • Flex (498) [RSS]
 • Home Automation (5) [RSS]
 • Jobs (116) [RSS]
 • JRun (14) [RSS]
 • Labs (43) [RSS]
 • LiveCycle (34) [RSS]
 • MAX (232) [RSS]
 • Mobile (120) [RSS]
 • Regular Expressions (17) [RSS]
 • RIA (21) [RSS]
 • SQL (40) [RSS]
 • Stuff (536) [RSS]
 • Tips (CF Studio) (80) [RSS]
 • Tips (CF) (795) [RSS]
 • Tips (Dreamweaver) (91) [RSS]
 • Tips (Flex Builder) (2) [RSS]
 • Using CF (162) [RSS]

Other BLOGs
 • Charlie Arehart
 • Lee Brimelow
 • Ray Camden
 • Christophe Coenraets
 • Sean Corfield
 • Mihai Corlan
 • Cornel Creanga
 • Mark Doherty
 • John Dowdell
 • Danny Dura
 • Enrique Duvos
 • Steven Erat
 • Kevin Hoyt
 • Serge Jespers
 • Adam Lehman
 • Duane Nickull
 • Miti Pricope
 • Andrew Shorten
 • Ryan Stewart
 • James Ward
 • Greg Wilson
 • Full As A Goog

RSS Feeds
 • Feed
 • Subscribe

Join my mailing list and find out about new books and other topics of interest.

Thoughts, ideas, tips, musings, and pontifications (not necessarily in that order) by Ben Forta ...
NOTE: This is my personal blog, and the opinions and statements voiced here are my own.

Viewing By Entry / Main
August 28, 2006

GetScheduledTasks() Function Returns Scheduled Task List

<cfschedule> is used to define and run ColdFusion scheduled tasks. For some reason the tag does not return a list of defined tasks, and a user on cf-talk asked for this functionality recently. So, until we update <cfschedule>, here is a UDF that returns a query containing the details about all scheduled tasks.

The bulk of this code (the regular expressions, funky nested looping, and so on) are the work of Michael Dinowitz (and I have retained his warnings about not doing what he is about to do).

<!--- Obtain scheduled tasks details --->
<cffunction name="GetScheduledTasks" returntype="query" output="no">

    <!--- Local vars --->
    <cfset var tasks="">
    <cfset var result=QueryNew('path,file,resolveurl,url,publish,password,operation,username,interval,start_date,http_port,task,http_proxy_port,proxy_server,disabled,start_time,request_time_out')>
    <cfset var OuterStart="">
    <cfset var InnerStart="">
    <cfset var qRETest="">
    <cfset var qRETestinner="">
    <cfset var ScheduleItem="">

    <!--- This call is undocumented --->
    <cfsavecontent variable="tasks">
        <cfschedule action="run" task="__list">
    </cfsavecontent>

    <!--- The start for each schedule entry --->
    <cfset OuterStart=1>

    <!--- Be super careful when using an infinite loop in this manner.
        Actually, never use an infinite loop in this manner. --->

    <cfloop condition="OuterStart">
        <!--- Each schedule item is a text string followed by an = followed by a double {.
            The end of the item also has a double }
            Getting only the elements in an item removed the need for a negative lookahead later --->

        <cfset qRETest=REFind('\w+={{(.+?})}}', tasks, OuterStart, 1)>
        <!--- If there is a result, use it.
            Otherwise break out of the loop. VERY IMPORTANT!!! --->

        <cfif qRETest.Pos[1]>
            <!--- This is the string containing all of the
                elements in a schedule item --->

            <cfset ScheduleItem=Mid(tasks, qRETest.Pos[2], qRETest.len[2])>
            <!--- Set the start past the schedule item found --->
            <cfset OuterStart=qRETest.Pos[2]+qRETest.len[2]>

            <!--- The start for each element of a schedule item --->
            <cfset InnerStart=1>
            <!--- Add a row. We don't have so specify as we'll be
                adding 1 per schedule item --->

            <cfset QueryAddRow(result)>
        
            <!--- Be super careful when using an infinite loop in this manner.
                Actually, never use an infinite loop in this manner. --->

            <cfloop condition="InnerStart">
                <!--- A schedule element is text followed by an = followed by
                    a value inside of {}. Even though the schedule item string
                    can be seen as a list, we don't know if there will be a
                    comma inside one of the elements so we're doing it the
                    hard but safe way. --->

                <cfset qRETestinner=REFind('(\w+)={([^}]*)}', ScheduleItem, InnerStart, 1)>
    
                <!--- If there is a result, use it.
                    Otherwise break out of the loop. VERY IMPORTANT!!! --->

                <cfif qRETestinner.Pos[1]>
                    <!--- The QuerySetCell will automatically assign the value to the last row added so no need to specify row. The second element of the RegEx return is the column name and the third is the value--->
                    <cfset QuerySetCell(result,
                                        Mid(ScheduleItem, qRETestinner.Pos[2], qRETestinner.len[2]),
                                        Mid(ScheduleItem, qRETestinner.Pos[3], qRETestinner.len[3]))
>

                    <!--- Set the start past the schedule element found --->
                    <cfset InnerStart=qRETestinner.Pos[1]+qRETestinner.len[1]>
                <cfelse>
                    <!--- Break out of our inner infinite loop --->
                    <cfbreak>
                </cfif>
            </cfloop>
        <cfelse>
            <!--- Break out of our inner infinite loop --->
            <cfbreak>
        </cfif>
    </cfloop>

    <cfreturn result>

</cffunction>

TrackBacks
There are no trackbacks for this entry.

No trackback URL. Trackbacks are only allowed via interactive form.

Comments
Just a note. In CF 8 you need to add a "paused" column to the query.
# Posted By Don Vawter | 9/12/09 11:01 PM

  © Copyright 1997-2009 Ben Forta, All Rights Reserved