samedi 4 avril 2015

Finding spring batch instances which are X days old

Currently I have restart spring-batch job in place which is running each hour and checking DB via JobExplorer for job instances which failed, it picks up latest job instance for job which is failed and restarts latest execution. This works fine but we have now new request to restart not only latest instance but all instances which fall in X day window and we should restart one at time from oldest one until it falls out of this window.


Example:



  • Job A has instance jobInstance1 which fail at 8pm

  • Job A has instance jobInstance2 which fail at 9pm

  • restart kicks in first time at 10pm and first restarts jobInstance1

  • jobInstance1 now succeed

  • restart kicks in second time at 11pm and restarts jobInstance2


I am thinking about two options:



  1. Use JobExplorer and combination of List<JobInstance> getJobInstances(String jobName, int start, int count); and int getJobInstanceCount(String jobName) throws NoSuchJobException; and to walk through list to find what I am looking for by checking start time

  2. Extend JdbcJobInstanceDao and write my own query against JOB_INSTANCE table joined with JOB_EXECUTION and use that


Is there better way to fetch all failed job instances of some job which are at most 3 days old and sort them oldest first?


What do you think about option 1 and 2 if there is no better way?


Aucun commentaire:

Enregistrer un commentaire