Spring batch job csv file reads recovery from a line in which it was not executed

The reader looks like this:

<bean id="cvsFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">

    <property name="resource" value="classpath:cvs/input/report.csv" />
    <property name="lineMapper">
        <bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
            <property name="lineTokenizer">
                <bean
                    class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
                    <property name="names" value="id,impressions" />
                </bean>
            </property>
            <property name="fieldSetMapper">
                <bean
                    class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
                    <property name="prototypeBeanName" value="report" />
                </bean>
            </property>
        </bean>
    </property>

</bean>

What I want to achieve is that if the read / task problem fails while reading the CSV file, then the next scheduled task should start from a line that it could not handle in the last execution. I can track the rows processed by the counter in the CustomProcessor process () function.

But any idea how to read the csv file from the last default state?

I want to start / restart a failed job manually. Should I implement SkipPolicy as described here http://thisisurl.com/spring-batch-skip-and-retry ?

(CSV , CSV)

+2
1

, :

, csv ?

jobParameters, batch_job_execution_params.

batch_job_execution .

/ . SkipPolicy, http://thisisurl.com/spring-batch-skip-and-retry?

, , restartability.

csv, RetryPolicy:

    <batch:step id="processing-step">
        <batch:tasklet>
            <batch:chunk reader="csv_reader"
                         processor="csv_processor"
                         writer="csv_writer"
                         commit-interval="5">
                <batch:retry-policy>
                    <bean class="org.springframework.retry.policy.AlwaysRetryPolicy" scope="step"/>
                </batch:retry-policy>
            </batch:chunk>
        </batch:tasklet>
    </batch:step>

Spring (, ). .

+1

Source: https://habr.com/ru/post/1524674/


All Articles