Nov 10th, 2008, 09:00 AM
What is best practices for skipping the remaining job from a tasklet?
I'm considering strategies for a simple batch line, which starts with checking a drop directory. Only if a new file is found should the rest of the steps proceed and an item reader (file) resource need to be injected.
I'm considering either of these two alternatives:
Alt 1) Perform directory polling outside SpingBatch and launch a job only if a file is found.
Alt 2) Implement directory scan as a tasklet and cancel the job if no file is found.
The problem with alt 2 is that throwing an exception causes the job to fail and results in a restart. The SkipLimitStepFactoryBean class is item oriented and is not suited for a tasklet doing directory scanning.
Question 1) Has anybody experience of something similar and would like to share lessons learned?
Question 2) Besides of implementing directory scanning myself, are there any good libraries that work nicely with SpringBatch? I have found JPoller, but it seems abandoned and not present in any Maven repo (mvnrepository).
Nov 10th, 2008, 09:05 AM
I'd suggest that the directory checking is not part of the spring batch 'workflow'. That's how I've implemented it.
Note that detecting a file drop is functionally equivilent to having a timer fire; these things are outside the purview of Spring Batch.
So, you have some timer that periodically checks a directory for a new file. If one is found, the batch job is kicked off with the file as input, otherwise the timer goes back to sleep. Capice?
Nov 10th, 2008, 09:09 AM
Originally Posted by chudak
I had a nagging feeling that this was the way to go, after struggling with skip logic configuration.
Do you have any pointers for directory scanning, besides JPoller or a fresh hack?
Nov 10th, 2008, 09:26 AM
I would check out Spring Integration, I can't remember the classname off the top of my head, but they a form of Message Channel that will poll a directory and turn the File object into a Message, you can then use that to kick off a Spring Batch job by using the File in the JobParameters.
Nov 10th, 2008, 09:50 AM
I wrote my own directory listener several years ago that we are using in several of our projects here. It dispatches to a pluggable listener on file (add/delete/change), has support for regex filename pattern matching and can be triggered using either a java timer or a quartz job.
Originally Posted by foobar17
Sounds like the spring integration may be better for you so you don't have to reinvent the wheel (SI didn't exist 2 years ago when I had this need). JPoller may work as well (it was a little overkill for my needs IIRC).
Last edited by chudak; Nov 10th, 2008 at 09:53 AM.
Tags for this Thread