Skip to main content
Known Participant
July 22, 2009
Question

Failover for scheduled task

  • July 22, 2009
  • 1 reply
  • 1396 views

hi,

i have 1 istance with some scheduled task. Now i'd like to have another server with another CF istance running in "cold backup", ready to accept request when the first server doesn't respond anymore.

The problem is with the scheduled task, if i configure them in both istances they will run twice.. There is a way (or a workaround) to launch only once the scheduled task?

i thought a workaround..

a shell script that check the virtual IP (that switch between two servers), if is assigned to his server, then will launch a wget of the scheduled task URL otherwise will exit.

In CF8 i have seen that i can suspend a scheduled task.. there is a way to launch command line a command to enable/disable scheduled task? some parameter in the jrun?

There are other solutions/workaround?

thanks in advance

    This topic has been closed for replies.

    1 reply

    July 22, 2009

    The adminapi doesn't hook into scheduled tasks.

    What you might consider is a simple table that you can time-stamp and read from in your scheduled task. If a certain amount of time has passed (whatever you deem unreasonable) then the second server can kick off it's task, otherwise it will simply skip processing.

    I.E.

    <cfquery name="qryGetLastTimeRan">

         SELECT last_run_time

         FROM heartbeat

    </cfquery>

    <cfif DateDiff("n",qryGetLastTimeRan.last_run_time, Now()) GT 30>

         DO PROCESSING

         POSSIBLY ALERT THAT SERVER 1 IS UNRESPONSIVE

         ETC...

    </cfif>

    Just a quick and dirty solution...

    clagioAuthor
    Known Participant
    July 22, 2009

    thanks for the proposal.. but are you sure this will work?

    if i well understood, i will have server 1 with my scheduled task, and server 2 with scheduled your script.

    when your script will run it will use the jrun of the second server and the qryGetLastTimeRan.last_run_time will simply check the last run of your script and not of my 1st server scheduled task..

    i'm right?

    July 22, 2009

    You would end up having the same scheduled task on both servers however, it would be slightly different:


    (SERVER 1)


    <!---


        YOUR CODE FOR THE TASK GOES HERE


    -->


    <cfquery>

        UPDATE heartbeat

        SET last_run_time = <cfqueryparam value="#CreateODBCTime(Now())#" CFSQLType="CF_SQL_TIME">

    </cfquery>


    (SERVER 2)

    <cfquery name="qryGetLastTimeRan">

         SELECT last_run_time

         FROM heartbeat

    </cfquery>

    <cfif DateDiff("n",qryGetLastTimeRan.last_run_time, Now()) GT 30>

    <!---


        YOUR CODE FOR THE TASK GOES HERE


    -->

    </cfif>

    (WHAT THIS WILL DO)

    As long as the scheduled task is ran successfully on 1, it will update the time stamp. Server 2 runs the process and verifies that 1 ran. If not, then 2 will run the process. You can code two to send out notifications that one is down etc... or just run the process. It's not a perfect solution, but it should get you through.

    NOTE:

    The DateDiff() checks for a thirty minute delay. You need to adjust this to what you deem appropriate and you need to make sure to stagger the scheduled tasks on the two ColdFusion instances.