Skip to main content
lovewebdev
Inspiring
April 22, 2012
Question

Make cfschedule run daily but random hours

  • April 22, 2012
  • 2 replies
  • 5679 views

I'm running a cfschedule at "daily" intervals, but is there anyway to get it to execute at random hours not every 24th hour from when i initially set it to run?

So say I set it daily, how can I get it execute on a random hour in the day as opposed to every 24th day?

The same applies for monthly, how can I get it execute on a random day monthly as opposed to every 30th day?

my code now:

<cfschedule action = "update"

    task = "sendit"

    operation = "HTTPRequest"

    url = "http://xyz.com/xyz/xyz.cfm"

    startDate = "#DateFormat(now(),'mmmm, dd, yyyy')#"

    startTime = "#TIMEFORMAT(now(),'hh:mm:ss')#"

    interval = "daily"

    resolveURL = "Yes"

    requestTimeOut = "600">

Thanks!

This topic has been closed for replies.

2 replies

Inspiring
April 22, 2012

I'm running a cfschedule at "daily" intervals, but is there anyway to get it to execute at random hours not every 24th hour from when i initially set it to run?

Why do you want to do this?

You could use the task code to update its own schedule each time it runs to be rescheduled for an random hour the following day.

--

Adam

lovewebdev
Inspiring
April 22, 2012

I'm setting a random reminder to be sent throughout the day,  but it shouldn't be sent at the exact time each day...

Im not an expert,  are we saying the other method isn't good?

@adam In terms of changing the schedule itself to do this what attribute should I be looking into it?

Inspiring
April 22, 2012

Just do a <cfschedule action="update"> with the new values (I don't think one can specify just a subset to upate, it'll need to be the whole lot, but do some experiementation...

--

Adam

Inspiring
April 22, 2012

Run the job at the start of the day/month.  However, amend the file being run to sleep for a random period of time.

lovewebdev
Inspiring
April 22, 2012

Wouldnt that skip it from executing if the schedule executes when the page is sleeping?

Or will it just subtract the sleeping seconds?

Also is this how you put a page to sleep,

<cfset thread = CreateObject("java", "java.lang.Thread")><cfflush> <cfset thread.sleep(5000)>

Also to get this to work so that its a random time daily, wouldn't I have to set the schedule to run for a certain amount of seconds as opposed to daily...