AdobeStock_455007340

GetScheduledTasks() Function Returns Scheduled Task List

Home » GetScheduledTasks() Function Returns Scheduled Task List

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 , 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).



















































14 responses to “GetScheduledTasks() Function Returns Scheduled Task List”

  1. Sami Hoda Avatar
    Sami Hoda

    Is this something you can ask for in the next version of ColdFusion? (hint, hint)

  2. Mitfahrzentrale Avatar
    Mitfahrzentrale

    Hi,
    for some reason the UDF gives an empty result set on CFMX 6.1.
    But the CF-Administrator shows my scheduled tasks.
    Does it only work on CFMX 7 ?
    Kind regards
    Thorsten

  3. Ben Forta Avatar
    Ben Forta

    Sami, yep, I’ve asked for this enhancement.
    Thorsten. Run that cfschedule line by itself and see if it returns data.
    — Ben

  4. King AdRock Avatar
    King AdRock

    Ben,
    What do you use for regular expression strings?

  5. Ben Forta Avatar
    Ben Forta

    KAR, I have no idea what you are asking, sorry.
    — Ben

  6. Michael Dinowitz Avatar
    Michael Dinowitz

    ColdFusion has 4 RegEx functions. 2 for find (REFind/REFindNoCase) and 2 for replace (REReplace/REReplaceNoCase). Most of the RegEx syntax are allowed within these functions and this is what was used in the example. Negative lookaheads are possible and were the original thought until a larger pattern was found and simpler code was written.
    If you need more RegEx power for things like positive and negative look-behinds, you can always leverage the power of the Java RegEx engine directly using CFOBJECT or CreateObject().

  7. Rahul Narula Avatar
    Rahul Narula

    The above UDF work for me on CF 7.0.1
    But I use this undocumented feature to get me the array of all defined scheduled task (without too much regex stuff )
    <cfscript>
    alltask=ArrayNew(1);
    taskService=createobject(‘java’,’coldfusion.server.ServiceFactory’).getCronService();
    alltask=taskservice.listall();
    </cfscript>
    <cfdump var="#alltask#">

  8. Michael Dinowitz Avatar
    Michael Dinowitz

    So when is Adobe going to stop giving us all this good stuff in an undocumented factory and instead document it? 😉

  9. Patrick Whittingham Avatar
    Patrick Whittingham

    Ben/Michael/Rahul –
    That’s a cool ‘features’ of servicefactory. Can one get that kind of information for ALL of cfquery(s), just like one sees in debug mode for a template. I need all of the queries/sql without giving the list of cfquery names. I’ve seen 1 hardcoded sql via servicefactory,but not all of the cfquery sq for a template. I need the sql,recordcount and time.

  10. Russ Spivey Avatar
    Russ Spivey

    that is a rad bit of code Rahul!

  11. Don Vawter Avatar
    Don Vawter

    Just a note. In CF 8 you need to add a "paused" column to the query.

  12. Charlie Arehart Avatar
    Charlie Arehart

    I found that in CF9 I needed to not only add paused (as Don mentioned) but also last_run and end_time. (We’re talking about just adding them to the end of the querynew function on line 7.)

  13. Don Vawter Avatar
    Don Vawter

    For cf9 you can use the CronService.listAll method in coldfusion.server.ServiceFactory
    http://stackoverflow.com/questions/2320396/how-to-get-list-of-scheduled-tasks-and-last-run-results-in-coldfusion

  14. Geoff Bowers Avatar
    Geoff Bowers

    Railo 3+ and CF10+ now offer a **list** action: <cfschedule action="list" returnvariable="qTasks">

Leave a Reply