Tracking Scheduled Tasks with Scheduler 1.1

One of the sites I work on went through a period where it ran very slowly (or even crashed) a few times a month. Each time, the problem generally started around three in the morning. As the site has several scheduled tasks, I was asked if any of them could be the culprit. At the time, I had no reliable way to answer that question. Now I do.

The site predates Scheduler.cfc, so my first act was to migrate all of the scheduled tasks to use that (easy to do). Next, I expanded the data being saved by Scheduler when it runs a task.

I can schedule a method of a component like this:

<cffunction name="init" access="public" output="no">
<cfargument name="Scheduler" type="any" required="yes">

<cfset variables.Scheduler = arguments.Scheduler>

<cfinvoke component="#variables.Scheduler#" method="setTask">
<cfinvokeargument name="Name" value="Send Articles Email">
<cfinvokeargument name="ComponentPath" value="sys.ArticleNotices">
<cfinvokeargument name="Component" value="#this#">
<cfinvokeargument name="MethodName" value="sendMessages">
<cfinvokeargument name="Interval" value="hourly">
<cfinvokeargument name="hours" value="6-18,20">
</cfinvoke>

<cfreturn this>
</cffunction>

Tasks in Scheduler are stored in schTasks. These can be retrieved by using Scheduler.getTaskRecords(), which can take any column as an argument to retrieve only matching records.:

  • TaskID: integer primary key
  • Name: unique name for the scheduled task
  • ComponentPath: unique name for the component
  • MethodName: name of the method to call on the component
  • Interval: Task interval (once, hourly, daily, weekly, monthly, or a number of seconds)
  • hours: list of hours in which the task can run
  • dateCreated: when the task was created

Scheduler.cfc keeps track of these tasks as well as a reference to the component itself.

Scheduler.cfc also keeps track of each time it executes a task in schActions. These can be retrieved by using Scheduler.getActionRecords(), which can take any column as an argument to retrieve only matching records:

  • ActionID: integer primary key
  • TaskID: id of the task
  • DateRun: when the task was run
  • ErrorMessage: any error message returned from the method
  • ErrorDetail: any error detail returned from the method
  • Success: true if no exception, false if an exception was returned
  • Seconds: number of seconds it took the method to execute
  • ReturnVar: any value returned by the method
  • TaskName (in method, but not table): Name of the task

For my purposes, the "Seconds" was the valuable piece of information as I was able to see how long my tasks were running and establish that none were running long enough to be the culprit.

In addition to retrieving data from the built in methods, I can create any ad-hoc data I want my just querying those tables directly.

Scheduler.cfc is part of the com.sebtools package which is open source and free for any use. Scheduler 1.1 is part of com.sebtools Build 7.

Related Blog Entries

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.