• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CFSchedule Overnight with one task (CF Enterprise 2016) ?

Explorer ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Silly question that I can't quite figure out:

 

I want to schedule a task via the CFAdmin panel to run a .cfm script every 30 seconds starting at 10pm and ending a 8:59am the following morning.

Right now, I am unable to figure out how to do this as one task.  Instead, I've had to set up a "daily" task that runs every 30 seconds starting at 10pm (with no end  specified), and then a second task (that runs the same .cfm script) that starts at 12am and ends at 9am.

 

Is there a way to do this as a single task instead of the two?  It's not a huge deal, just trying to see if there an obvious way to do that my brain is not seeing at the moment.

 

Thanks!

Views

524

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 06, 2021 Jun 06, 2021

Copy link to clipboard

Copied

What about using, in the ColdFusion Administrator, settings similar to the following:

BKBK_0-1622984352548.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 06, 2021 Jun 06, 2021

Copy link to clipboard

Copied

Bad news/good news on this.

 

1) First, I'm afraid that won't work, BKBK. The first problem is pretty easily solved (and was perhaps just an oversight): you'd get a prompt saying that "You need to enter a valid Start Date in order to proceed." But the bigger challenge is you would then get a prompt that "the end time must be after the start time."  But I agree it would be nice if CF was able to support that. 🙂

 

2) So for Two Edge's need, it seems there's no choice but to setup two tasks, one for the 10:00:00 PM to  11:59:00 PM and another for 12:00:00 AM to 08:59:00 AM. Duplication has its drawbacks, but I don't think there's another option.

 

3) Finally, someone might have wondered if it may be possible to use the "crontime" feature on that CF Admin page (crontime for tasks was introduced in CF10). I can share what I have found here on that. Read on, if interested.

 

3a) While it is indeed posible to set a cron time that represents every 30 seconds, sadly its feature for setting the hours also does not work with the final/second hour being earlier than the first. I tried it.

 

3b) If someone reading this is aware of crontime and would say that it doesn't support controlling seconds, actually the CF scheduled task mechanism runs via the open source Quartz library, which DOES in fact have support for seconds (see docs here and here, which are for version 2.2.2, which is the closest doc version to what CF2021 runs, which is version 2.2.1).  There's also a nice online tool (free) to help build such a crontime for quartz, here: 
https://www.freeformatter.com/cron-expression-generator-quartz.html 

 

So first to run something every 30 seconds (every day all day), one could use this:

 

*/30 * * ? * * * 

 

And to run it from one given hour to another, that could be specified as a range in place of the 3rd *, such as to run from 10a to 10p:

 

*/30 * 10-22 ? * * * 

 

And FWIW, that freeformatter site has a nice feature to to turn a cron pattern into words, and that would show as "Every 30 seconds starting at second 00, every minute, every hour between 10am and 22pm, of every day".

 

3c) But again TwoEdge needed 10p-9a, and while the CF Admin accepted */30 * 22-9 ? * * *,  I confirmed that it started the task running BEFORE my 10p, so that won't work. (And that freeformatter site tool would NOT allow the 22-9, complaining "(Hours) - Unsupported value '22-9' for range. Accepted values are 0-23".)

 

3d) Further, I saw some resources suggesting that some tools accept two crontimes separated by a comma, but again while the CF Admin ALLOWED that, I confirmed that it ONLY honored the time for the FIRST crontime, not the second. 

 

The cron feature is indeed way more powerful than most realize--but it's also quite intimidating in that power. Tools like that above can really help. But again in this case it seems it would not help with the specific problem.

 

4) Twoedge, let us know if the two task approach works well enough for you, or I'll be interested to hear if anyone has a better idea, or if I missed something about the crontime.


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 07, 2021 Jun 07, 2021

Copy link to clipboard

Copied

@Charlie Arehart , the suggestion I gave does in fact work. I took it for granted that TwoEdge will fill in the start-date and end-date.

 

@TwoEdge , the following settings are for a full, working example I created just now. It took me 6 minutes.

 

The index.cfm page consists of one line of code:

<cflog text="#now()#" file="schedulerTest" type="information">

BKBK_0-1623054290624.png

 

The result:

BKBK_1-1623054558268.png

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 07, 2021 Jun 07, 2021

Copy link to clipboard

Copied

I'm not seeing how that solves his problem. 


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 09, 2021 Jun 09, 2021

Copy link to clipboard

Copied

quote

I'm not seeing how that solves his problem. 


By @Charlie Arehart

 

The requirements TwoEdge gave are:

 

schedule a task via the CFAdmin panel to run a .cfm script every 30 seconds starting at 10pm and ending a 8:59am the following morning. 

 

To solve this, just adapt my example to:

Start Time 10:00:00 PM        End Time 08:59:00 AM

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 09, 2021 Jun 09, 2021

Copy link to clipboard

Copied

OK but just to be clear, BKBK, if you are proposing that as one task, it won't work. I shared originally how cf won't accept the stop time being before  the start time.

 

But let's see what twoedge can do with all the options seems we three have shared. 🙂 


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 10, 2021 Jun 10, 2021

Copy link to clipboard

Copied

quote

OK but just to be clear, BKBK, if you are proposing that as one task, it won't work.


By @Charlie Arehart

 

Oh, my bad. I see it just now:

BKBK_0-1623312886433.png

I didn't expect that of ColdFusion. Lame. 😞

 

Then TwoEdge could indeed use the Crontime option, as you said. The Cron expression I obtained from  https://www.freeformatter.com/cron-expression-generator-quartz.html is 

0/30 0 0,1,2,3,4,5,6,7,8,22,23 ? * * *

 

BKBK_1-1623313071420.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

quote

Duplication has its drawbacks, but I don't think there's another option.

 

By @Charlie Arehart

 

An option that springs to my mind is to not schedule the job to run every 30 seconds.

I would create a script that is scheduled to start at 10pm and then loop inside the script until 8am the next day.

in pseudo-code:

while (not 8am the next day)
  do work
  sleep for 30 seconds
loop

If it is important for the work to be done exactly every thirty seconds, it would be necessary to time the work done and subtract it from the sleep time.

If it is possible that the work in the loop could take more than 30 seconds you could spin up a new thread to do the work, although this requires CF Enterprise Edition.

Note that it will be very important to add a cfsetting at the beginning of the script to set the requestTimeout to avoid time out issues.

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 09, 2021 Jun 09, 2021

Copy link to clipboard

Copied

Yep, Eddie. That's indeed another option, though two tasks does seem easier. 🙂  Still, we 3 have given twoedge and future readers plenty to consider. 


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 12, 2021 Dec 12, 2021

Copy link to clipboard

Copied

I have made a Scheduler Feature Request. Please go there and place your vote.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 12, 2021 Dec 12, 2021

Copy link to clipboard

Copied

Just voted. 


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 14, 2021 Dec 14, 2021

Copy link to clipboard

Copied

LATEST

+1

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation