views:

73

answers:

3

I have a CFC method that I would like to run at an interval of 30 seconds. However, the problem is ColdFusion won't let me schedule a task that runs at an interval of 60 seconds or lower. Does anyone have a suggestion about how I can (and should) accomplish this?

To preemptively answer the question "What happens when your script runs longer than 30 seconds," or any other question like that, I have already taken all that under consideration and it is not a concern.

I'm running ColdFusion 8.0.1 (w/ hotfix 4) on Windows Server 2003 (IIS6). As a side note, I'm using Java 1.6u21 as my JVM for ColdFusion.

Thanks in advance.

+4  A: 

You could use curl and schedule a task on the server Win or nix.

cfEngineers
This was one of my first thoughts. I won't rule it out completely, but I would rather keep everything in CF if at all possible. Thanks for the answer.
Joe D
+1  A: 

Are you really interested in your task running twice a minute, or are you just looking to reduce the latency in detecting changed or new data? If it's the latter, you could look at using CF Event Gateways to detect exactly when to run. If this is the case you'd have far less churn on your server, since you'd run that CFC method immediately upon some event and not just poll endlessly for data.

bpanulla
This application needs to query several data sources and constantly update information to be displayed on clients written in Flex. Unfortunately event gateways don't fit the bill, though I think they're a pretty cool feature.
Joe D
+5  A: 

The only way to do this is with some manual editing of the file for your scheduled tasks.

So:

  1. Create the scheduled task with an interval of say 5 mins.
  2. Open the file called neo-cron.xml in the lib directory of your CF install. You might want to back it up first.
  3. Search for the name of your scheduled task. It's a big chunk of XML so you might like to format it and search for it in a XML editor.
  4. A little after the name of the task you should see something like this: <var name="interval"><string>300</string></var>. This is the number of seconds between when the task runs. It's in seconds here, so you can manually adjust it to 30 and then save the file and close it.

This will still show as 1 min in the CF admin but it should run every 30 seconds - add logging to prove it if you wish!

Not that if you edit any other scheduled task using CF admin your manual changes will be unaffected, but if you edit the actual task you manually adjusted it will overwrite your changes.

Hope that helps!

Ciaran Archer
Similar trick can be done with `cfschedule` tag too, but at least CF9 wiped this task after first execution -- so I've considered the solution invalid.
Sergii
This is really neat! I didn't know you could do that. Thanks!
Joe D