I had a hosting provider recently ask me if there was a way to automatically remove disabled or expired scheduled tasks without having to go through the ColdFusion administrator, because he had many servers and each server had many scheduled tasks so it would have been a pretty large chore to maintain this manually.

ColdFusion scheduled task information is stored as WDDX in the file \cfusionmx7\lib\neo-cron.xml

Below is the script I created that will cleanup the neo-cron.xml.

I would suggest that you create a back up of your neo-cron.xml file before you start using this, just in case.

<!--- Read the current neo-cron file --->
<cffile action="READ"
   file="c:\cfusionmx7\lib\neo-cron.xml"
   variable="neocronwddx">


<!--- convert the wddx to a coldfusion structure --->
<cfwddx action="WDDX2CFML" input="#neocronwddx#" output="neocron">

<!--- dump current neo-cron --->
<cfdump var="#neocron#">

<!--- loop through the structure and remove disabled or expired entries --->
<cfloop collection="#neocron[1]#" item="i">
   <cfif neocron[1][i].disabled eq "YES"
      or (structkeyexists(neocron[1][i],"end_date")
         and datecompare(neocron[1][i].end_date,now()) eq -1)>

      <cfset structdelete(neocron[1],i)>
   </cfif>
</cfloop>

<!--- dump updated neo-cron --->
<cfdump var="#neocron#">

<!--- convert the structure to wddx --->
<cfwddx action="CFML2WDDX" input="#neocron#" output="neocronwddx">

<!--- save the new neo-cron file --->
<cffile action="write"
   file="c:\cfusionmx7\lib\neo-cron.xml"
   output="#neocronwddx#"
   addnewline="No"
   nameconflict="OVERWRITE">

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Scott Bennett's Gravatar It should be noted that you wouldn't normally want to hard code something like the file path that is in the example above. If you are really in the need for something like this, I would suggest you make a custom tag or a CFC, that could add, edit, and/or delete the scheduled tasks as you need. Also I would use the #server.coldfusion.rootdir# to get the coldfusion root folder in your cffile tags instead of hard coding the "C:\cfusionmx7" portion of the file.

Additionally, I would recommend that you put named cflocks around the process to protect the integrity of the file, and incorporate adequate error handling to ensure a corrupt version of the neo-cron.xml file does not get saved.

Lastly, to re-emphasize a point I made in entry, any time you write code to edit any system file, you will want to make sure you have a back up of the original file in the event you mess it up.
# Posted By Scott Bennett | 11/7/07 6:21 PM
Dan Kelly's Gravatar This approach enables me to lookup the interval and offer the user an interface to review it and change it using cfschedule:

<cffile action="read" file="#server.coldfusion.rootdir#\lib\neo-cron.xml" variable="wddxNeocron">
<cfwddx action="WDDX2CFML" input="#wddxNeocron#" output="sctNeocron">

<cfset theTarget = "timeMonitor">
<cfset theInterval = "">
<cfoutput>
<cfloop collection="#sctNeocron[1]#" item="i">
   #i# #sctNeocron[1][i].interval#<br/>
   <cfif i eq theTarget>
      <cfset theInterval = sctNeocron[1][i].interval>
   </cfif>
</cfloop>
# Posted By Dan Kelly | 7/2/09 6:05 PM
 
Home | Blog | Portfolio | Contact | © 2001 - 2007 The ColdFusion Guy - Scott Bennett. All rights reserved.
BlogCFC was created by Raymond Camden. This blog is running version 5.9.