Announcement Announcement Module
Collapse
No announcement yet.
What is best practices for skipping the remaining job from a tasklet? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    /jens

  • #2
    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?

    Comment


    • #3
      Originally posted by chudak View Post
      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?
      Thanks!
      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?

      /jens

      Comment


      • #4
        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.

        Comment


        • #5
          Originally posted by foobar17 View Post
          Thanks!
          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?

          /jens
          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.

          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, 10:53 AM.

          Comment

          Working...
          X