Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run a ColdFusion scheduled task at an interval <60 seconds?

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.

like image 645
Joe D Avatar asked Jul 28 '10 14:07

Joe D


3 Answers

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!

like image 72
Ciaran Archer Avatar answered Oct 24 '22 06:10

Ciaran Archer


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

like image 45
cfEngineers Avatar answered Oct 24 '22 06:10

cfEngineers


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.

like image 39
bpanulla Avatar answered Oct 24 '22 05:10

bpanulla