简体   繁体   English

Spring Batch中的作业执行已过期

[英]Expired job executions in Spring Batch

Problem 问题

Users can submit data to generate a report, which triggers a spring-batch job. 用户可以提交数据以生成报告,该报告将触发春季批量作业。 If the same data is submitted (by the same user or another user) the same report should be generated such that Spring Batch doesn't start a new job, under the premise that the report has already been generated. 如果(同一用户或另一用户)提交了相同的数据,则应在生成报告的前提下,生成相同的报告,以使Spring Batch不会启动新作业。

To make matters a little more complicated, generated reports expire after 90 days. 更复杂的是,生成的报告会在90天后过期。 The idea behind this is that the data gleaned from various web services used to build the report is likely out of date. 其背后的想法是,用于构建报告的各种Web服务收集的数据可能已过时。 Therefore, after 90 days the report should be re-generated using new data from those web services. 因此,在90天后,应使用这些Web服务中的新数据重新生成报告。

Questions 问题

  1. When a job has already run, how can I discover the job execution id for that job? 作业已经运行后,如何找到该作业的作业执行ID? This id is used in the URL to uniquely identify a report. URL中使用此ID来唯一标识报告。 JobExplorer is severely limited in querying Spring Batch data. JobExplorer在查询Spring Batch数据方面受到严格限制。

  2. How can I trigger another instance of the job only after 90 days? 仅在90天后如何触发该作业的另一个实例? The issue is that given duplicate job parameters, a JobInstanceAlreadyCompleteException will be thrown. 问题是,给定重复的作业参数,将抛出JobInstanceAlreadyCompleteException Must I encode the 90 days has an extra identifying parameter, or is there an easier way? 我必须对90天编码进行编码,是否需要额外的识别参数,还是有更简单的方法?

Clean up old jobs must be done using business methods as well as for expired reports. 清理旧作业必须使用业务方法以及过期的报告来完成。
After this premise you can try a different path to solve your problem: 在此前提下,您可以尝试其他方法来解决您的问题:

  1. Every user launch a different job, with same report properties but an extra job-parameters to make every jobs different 每个用户启动一个具有相同报表属性的不同作业,但需要额外的作业参数以使每个作业都不同
  2. First step is to check - using business method - if there is a running job for that report ; 第一步是使用业务方法检查-该报表是否正在运行; in this case notify user he have to wait or retry later (use a decider) 在这种情况下,通知用户他必须等待或稍后重试(使用决策程序)
  3. Second step is to check if there is a completed - not expired - report using a business method;if so retrieve it and show to user (use a decider as for step 2) 第二步是使用业务方法检查是否有完成的报告(未过期);如果有,请检索并显示给用户(使用第2步中的决定器)
  4. Generate report (delete old, if necessary) 生成报告(如有必要,删除旧文件)
  5. Show report to user. 向用户显示报告。

Of course, generated report metadata tables are different from SB tables and should be accessed using DAO related to domain context (the report in your case). 当然,生成的报告元数据表与SB表不同,应该使用与域上下文相关的DAO(在您的情况下为报告)进行访问。

Can this a valid alternative? 这可以替代吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM