Jon
Jon

Reputation: 10503

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.

To make matters a little more complicated, generated reports expire after 90 days. The idea behind this is that the data gleaned from various web services used to build the report is likely out of date. Therefore, after 90 days the report should be re-generated using new data from those web services.

Questions

  1. When a job has already run, how can I discover the job execution id for that job? This id is used in the URL to uniquely identify a report. JobExplorer is severely limited in querying Spring Batch data.

  2. How can I trigger another instance of the job only after 90 days? The issue is that given duplicate job parameters, a JobInstanceAlreadyCompleteException will be thrown. Must I encode the 90 days has an extra identifying parameter, or is there an easier way?

Upvotes: 0

Views: 686

Answers (1)

Luca Basso Ricci
Luca Basso Ricci

Reputation: 18411

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)
  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).

Can this a valid alternative?

Upvotes: 1

Related Questions