Git Product home page Git Product logo

naver-sport-news-batch-v2's Introduction

Spring Batch 에러 대응 전략


기존의 배치 로직

image

  • 기본 로직을 위와 같이 구성하였습니다.

image

  • Chunk 를 이용해 데이터를 분할하여 처리합니다.



마주친 에러 상황

image

  • 기존에 글자 수에 대한 유효성 처리를 할 수도 있었지만 만약에를 가정하여 설명을 진행하겠습니다.



어떤식으로 대응을 하고 싶었냐면요

  • chunk 3 개에 대한 처리 중에 1 개에 데이터에서 에러가 발생을 한다면
    • 정상 데이터 2개는 정상 처리 되도록 하고 싶었습니다.
    • 에러 데이터 1개는 특정 테이블에 에러 정보를 저장해놓고 싶었습니다.



같은 에러는 보지 않도록 예외 처리하기

  • 에러 데이터는 skip 하도록 SkipPolicy 를 구현하였습니다.
@Component
public class NaverSportNewsTitleSkipPolicy implements SkipPolicy {

    @Override
    public boolean shouldSkip(Throwable throwable, long skipCount) throws SkipLimitExceededException {

        if(throwable instanceof DataIntegrityViolationException){
            return true;
        }

        return false;
    }
}

  • 에러 데이터는 특정 테이블에 저장할 수 있도록 SkipListener 를 구현하였습니다.
@Component
@RequiredArgsConstructor
public class NaverSportNewsTitleSkipListener<T, S> implements SkipListener<T, S> {

    private final JdbcTemplate jdbcTemplate;

    @Override
    public void onSkipInRead(Throwable t) {
        jdbcTemplate.update("INSERT INTO NAVER_SPORT_NEWS_TITLE_ERROR (error) VALUES(?)", t.getMessage());
    }

    @Override
    public void onSkipInWrite(S item, Throwable t) {
        jdbcTemplate.update("INSERT INTO NAVER_SPORT_NEWS_TITLE_ERROR (error) VALUES(?)", t.getMessage());
    }
}

naver-sport-news-batch-v2's People

Contributors

soobinjung avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.