July 10, 2004

Looking at the scheduled tasks without the CFAdmin

Here is a nice little cfc to get access to the CF Scheduler tasks running on your cf box without having to utilize the administrator.

<cfcomponent displayname="CFMX Scheduled Tasks"
hint="CFMX Scheduled Tasks editor"
lastUpdated="2004-07-09"
author="Elyse Nielsen">

<!--- Initialization --->
<cfset THIS.lockname = CreateUUID()>
<cflock name="#THIS.lockname#" type="exclusive" timeout="10">
<cfscript>
this.factory = CreateObject("java", "coldfusion.server.ServiceFactory");
this.cron_service = this.factory.CronService;
this.Services = this.cron_service.listALL();
</cfscript>
</cflock>
<cfif not IsArray(this.Services)>
<cfthrow message="The template '#lcase(getfilefrompath(getcurrenttemplatepath()))#' can't initialize.">
</cfif>

<cffunction name="getScheduledTask" access="public" output="false" returnType="any"
hint="Returns the structure of the Scheduled Task if found by name">
<cfargument name="taskname" type="string" required="true">
<cflock name="#THIS.lockname#" type="exclusive" timeout="10">
<cfloop from="1" to="#ArrayLen(this.Services)#" index="i">
<cfif this.Services[i].task IS taskname>
<cfreturn this.Services[i]>
</cfif>
</cfloop>
</cflock>
<cfreturn "">
</cffunction>

<cffunction name="showScheduledTasks" access="public" output="false" returntype="array" hint="I return an array of structures of the scheduled tasks">
<cflock name="#THIS.lockname#" type="exclusive" timeout="10">
<cfreturn this.Services>
</cflock>
</cffunction>

</cfcomponent>


One can use cfschedule to accomplish the update, deleting, or running information.

One aside, I wish that that there was a way to add a isDisabled function for times when one needs to have the cron utility stopped. This would be a great feature in Blackstone or the next version. IMHO, it beats having to play with the end dates of the tasks.

Posted by Elyse at July 10, 2004 2:54 PM | TrackBack
Comments

Can one use this to add/update scheduled tasks.

- Pat

Posted by: Patrick Whittingham at July 11, 2004 11:31 AM

If only methods like these could be used for managing multiple servers/cfadmin, instead of having to manage each server seperately.

Like for example turning trusted cache on/off for deployment of code...

Nice piece of code, I'm going to play with it.

Posted by: Craig M. Rosenblum at July 12, 2004 10:07 AM
Post a comment









Remember personal info?