configuring multiple versions of job in spring batch

时间:2016-07-11 22:24:07

标签: spring-batch

SpringBatch seems to be lacking the metadata for the job definition in the database.

In order to create a job instance in the database, the only thing it considers is jobName and jobParamter, "JobInstance createJobInstance(String jobName, JobParameters jobParameters);"

But,the object model of Job is rich enough to consider steps and listeners. So, if i create a new version of the existing job, by adding few additional steps, spring batch does not distinguish it from the previous version. Hence, if i ran the previous version today and run the updated version, spring batch does not run the updated version, as it feels that previous run was successful. At present, it seems like, the version number of the job, should be part of the name. Is this correct understanding ?

1 个答案:

答案 0 :(得分:1)

框架通过作业名称和(识别)作业参数的唯一组合来识别每个作业实例是正确的。

通常,如果作业失败,您应该能够使用相同的参数重新运行以重新启动失败的实例。但是,您无法重新启动已完成的实例。来自文档:

  

如果执行失败,可以多次重启JobInstance,并且生命周期在首次成功执行时结束。尝试执行已成功完成的现有JobIntance将导致错误。如果作业无法重新启动,则尝试重新启动失败的JobInstance也会引发错误。

所以你是对的,相同的工作名称和识别参数不能多次运行。无论工作执行的业务步骤如何,设计框架都会阻止这种情况。再一次,忽略你的工作实际上做了什么,这是它的工作方式:

1) jobName=myJob, parm1=foo   , parm2=bar -> runs and fails (assume some exception)
2) jobName=myJob, parm1=foo   , parm2=bar -> restarts failed instance and completes
3) jobName=myJob, parm1=foo   , parm2=bar -> fails on startup (as expected)
4) jobName=myJob, parm1=foobar, parm2=bar -> new params, runs and completes

我们使用的“最佳实践”如下:

  • 每个作业实例(通常由我们正在处理的运行日期或文件名定义)必须定义一组唯一的参数(否则它将根据框架设计失败)
  • 每天运行多次但只是扫描工作表或某事的作业使用增量器传递一个整数参数,每次成功完成后我们会增加1
  • 在推送影响作业的代码更改
  • 之前,必须重新启动或放弃任何失败的作业实例