Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
269 views
in Technique[技术] by (71.8m points)

java - How to run spring batch job in scheduled mode in 1 given UAT server, but run manual job in all 3 given UAT servers?

This is related to Spring Batch Scheduling Problem.

I have 3 UAT servers (UAT1, UAT2 & UAT3). The task is to run the scheduled batch job in UAT3 server only but while I run a batch job by manually hitting the endpoint url, it should run in all 3 servers. We have used old Batch Executor framework approach. We have an endpoint java class for exposing the endpoint url for manual run, executor class for batch run and configured the scheduling using batch-contxt.xml file. As it is a bit tightly coupled, any change is affecting both manual & scheduled run.

How to modify the approach to include the above problem using spring batch concepts?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use separate yaml configurations based on environment profile and control based on a property. For example something like this.

#yaml file
jobs.importXMLJob.enable = true

@Value("${jobs.importXMLJob.enable}")
    private boolean jobXMLEnable;

@Scheduled(cron = "${batch.cron}")
    public void myJob() {
        if (jobXMLEnable) {
         UAT3 Job
      }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...