Skip to content

cfschedule delete – workaround

by Mike on August 18, 2006

Last week I learned that cfschedule has some annoying behavior when trying to call the delete action. If a scheduled task tries to delete itself (or update itself) through the cfschedule tag, it won’t actually delete the task and will continue to run until the server is restarted. This post describes a way for a scheduled task to delete itself.

This has been identified as a known issue in ColdFusion MX and is addressed in a TechNote. Macradobe suggests that we “Delete tasks through cf administrator” or “restart the cf server”. Neither one of these is an option for me if I want to programmatically delete my task.

The Adobe techNote is somewhat misleading, it turns out that delete does work through the cfschedule tag, but the problem arises when the scheduled task tries to delete itself.

The solution? Since cfschedule – delete works on a normal http request, but not on a “scheduled” http request, we need to make an asyncronous HTTP call from the task. This can be chieved using a cool tool called asyncHTTP written by Mark Mandell (Look at the blog posting here)

Now, within the request that is called from the scheduled task, I can include the following code.






The code to delete the scheduled task will now work…


   
   

   

   
   

Implementing this functionality allows us to process a queued stack in the background then delete the task when it’s complete. This is a powerful tool that allows us to execute code at a scheduled time, then continue executing until a condition has been met.

From → ColdFusion

6 Comments
  1. Mike,

    I would never have thought of using it this way! That’s a really good idea.

    Glad to see you found it useful :oD

  2. Mike,

    I have been stumpped by this problem for SO LONG. Thank you thank you! I love doing things programmatically.

  3. Mike,

    Quick question: How come you cannot just do a CFHttp call from the scheduled task to the page that deletes the task. Is it because you can’t delete the task from another page if the task itself is still running?

  4. Ben-
    Good point, I think you might be on the right track. It would make sense that the task can’t be deleted if it is still running, and in the CFHttp example, the request is synchronous, which makes it a catch 22 (request can’t finish until the cfhttp returns, and scheduler can’t be deleted if request is running).

    It would be interesting to run some tests to see if the asynch request would fail if the scheduled task continues to do processing after you make the http call. In that case you may need to implement a lock to make sure the scheduler request is not currently running.

  5. It would be interesting to run some tests to see if the asynch request would fail if the scheduled task continues to do processing after you make the http call.

Comments are closed.