使用具有相同作业名称的REST在spring batch admin中运行多个作业

时间:2013-04-23 22:16:09

标签: spring spring-batch-admin

我正在使用Spring Batch Admin为我们的系统运行批处理作业。我们必须多次经营这些工作。我正在使用spring batch admin的rest接口。我使用Spring RestTemplate开始一项新工作。

RestTemplate tpl = new RestTemplate();
tpl.postForLocation(Constants.SPRING_BATCH_ADMIN_URL + "/jobs/myBatchJob;

这可以启动第一个作业,但在后续作业中,请求不会启动作业的新实例。在作业配置文件中,我有一个jobParmatersIncrementer定义

<job id="myBatchJob" xmlns="http://www.springframework.org/schema/batch"
    restartable="true" incrementer="jobParametersIncrementer">
    <bean id="jobParametersIncrementer"
        class="org.springframework.batch.core.launch.support.RunIdIncrementer" />

我尝试将postForLocation更改为

List<JobInstance> jobInstances = jobExplorer.getJobInstances("myBatchJob", 0, 30);
JobParameters jobParameters = jobInstances.get(0).getJobParameters();
RunIdIncrementer runIdIncrementer = new RunIdIncrementer();
JobParameters jobParameters = runIdIncrementer.getNext(jobParameters); 
RestTemplate tpl = new RestTemplate();
tpl.postForLocation(Constants.SPRING_BATCH_ADMIN_URL + 
    "/jobs/myBatchJob?launch=Launch&{parameters}",
    "runid",
    jobParameters.toString());

通过单击启动按钮从弹簧批处理管理页面开始工作。这是在参数编辑框

run.id(long)=1

如何在多个Web应用程序中多次运行Spring Batch Admin中的作业?

1 个答案:

答案 0 :(得分:0)

您可以在请求正文中传递参数 jobParameter ,它带有您的元组

jobParameters=run.id(long)=123

并将其url编码到post请求中。这是我的jquery解决方案。

$.post('<url>/jobs/myBatchJob', 'jobParameters=' + encodeURIComponent('run.id(long)=123')).done(function() {
   // do something
});