Announcement Announcement Module
No announcement yet.
Best way to disable scheduled task on particular server in cluster Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Best way to disable scheduled task on particular server in cluster

    I've inherited a 3rd party developed web application which sends out emails through scheduled tasks supported in Spring 3x. Each task is configured to be run via a cron expression passed into the application from the it's META-INF/context.xml As we have 2 production servers in our setup with 2 application contexts existing, both run the scheduled tasks, resulting in duplicate emails being sent out.

    I need a solution whereby the jobs do not run on one of the servers. I realise this means we have no failover should the server go down, but the application is probably going to be recoded, so this is more of an urgent fix.

    Thinking about it, I could probably...
    • specify a context parameter in tomcat/conf/context.xml which could be used as a flag to determine if the tasks should run on that server
    • specify a context parameter in the tomcat/conf/context.xml where I don't want it to run which sets the cronexpression to some distant date and for other hosts rely on the META-INF/context.xml cron expression value.
    • somehow not load the scheduling application context.xml files when the application starts up on a specific host

    Should I do it the first way, I need to know how I can use this flag to disable the jobs from running without the need to edit the actual application code.
    The second way is appealing but feels pretty dirty
    The third is ideal but I don't want to have to package a specific war file but rather stop Spring from loading the application-context.xml related to the scheduler when it is starting up.

    Does anyone have any other suggestions?


  • #2
    As I said, ideally I don't want to include any scheduler application context files for a specific host, yet I don't want to have to deploy a different war. I was wondering if I could create a dummy application context file and include this based on an environment variable.

    So I could do...

    <import resource="scheduling-${env.scheduling.param}-config.xml"/> which if the value was false, would just include an empty file or if it was true, include an xml with all the scheduling beans.