Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring batch generating reports

Tags:

spring-batch

I would like to generate a summary report at the end of my batch execution.

For ex: I have an ItemProcessor which receives accountId.

for every accountId: get MarketplaceId's for every marketplaceId: call real time availability

At the end of batch execution I need to provide a nice summary in a file that shows,

  • Number of accounts processed
  • Number of marketplaceIds for each accoutId
  • Number of marketplaceIds that failed to get real time availability
  • Time took for processing one accountId

Question

  1. Where do I persist those intermediate results ie. the different count on each iteration
  2. How would I get those counts to the next step which is just a summary file writer

Would be really great if you provide any directions.

Thanks.


1 Answers

write a tasklet to prepare a nice summery and put that tasklet as last step in the Job

     <step id="summeryFile" >
        <tasklet ref="summaryFilePreparationTasklet"/>
    </step>

and Bean Configuration is

<bean id="summaryFilePreparationTasklet" class="com.baji.batch.SummaryPreparationFile">

and Class file is

 package com.baji.batch;

    import org.springframework.batch.core.StepContribution;
    import org.springframework.batch.core.scope.context.ChunkContext;
    import org.springframework.batch.core.step.tasklet.Tasklet;
    import org.springframework.batch.repeat.RepeatStatus;

    /**
     * @Author
     * Bhaji Shaik
     * May 30, 2015
     */
    public class SummaryPreparationFile implements Tasklet {

        @Autowired
private Holder holder;
        @Override
        public RepeatStatus execute(StepContribution arg0, ChunkContext chunkContext) throws Exception {
                    holder.getResults1();       
            //Write your own code to Prepare a neat summary preparation File
            return null;
        }

    }

Holder Class is

 import org.springframework.stereotype.Component;

    @Component
    public class Holder {
        private List<Integer> results1;
        private List<Integer> results2;

         //Setter and getter methods
    }
like image 87
Baji Shaik Avatar answered Jun 02 '26 19:06

Baji Shaik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!