Spring Batch 5.x 를 사용하였습니다.

사람인 api, 원티드 사이트 크롤링을 통하여 복수의 채용사이트들의 정보를 받아와

여러사이트를 찾아다니며 채용공고를 확인하는 수고를 덜 수 있습니다.

Request UI

Untitled

Response UI

Untitled

기존 Tasklet

@Bean
    @StepScope
    public Tasklet taskletSaramin() {
        return (contribution, chunkContext) -> {
            System.out.println("사람인 테스크렛");
            //TODO: 사람인 공고 기간 필터로직 추가
            /**
             * @param sectorCode 백엔드 84, 프론트 92, 풀스택 2232
             */
            SaraminApiManager.saraminStatistic(84);
            SaraminApiManager.saraminStatistic(92);
            SaraminApiManager.saraminStatistic(2232);
            return RepeatStatus.FINISHED;
        };
    }
@StepScope
    @Bean
    public Tasklet taskletStatistic() {
        return (contribution, chunkContext) -> {
            List<JobResponseDto> pureSaram = SaraminApiManager.getJobResponseDtos();
            for (JobResponseDto dto : pureSaram) {
                try {
                    jobStatisticService.create(dto);
                } catch (IllegalStateException e) {
                    log.error(e.getMessage());
                }
            }
            return RepeatStatus.FINISHED;
        };
    }

Chunk Processing

@Bean
    @JobScope
    public Step chunkstep(JobRepository repository) {
        return new StepBuilder("chunk", repository)
                .<JobResponseDto,JobResponseDto>chunk(1000, transactionManager)
                .reader(saraminReader())
                .processor(process())
                .writer(saraminWriter()).build();
    }

    @Bean
    @StepScope
    public ItemReader<JobResponseDto> saraminReader() {
        // 검색일 최소, 최대 값 설정으로 이후 값만 받아오기
        SaraminApiManager.saraminStatistic(84);
        SaraminApiManager.saraminStatistic(92);
        SaraminApiManager.saraminStatistic(2232);
        List<JobResponseDto> jobResponseDtos = SaraminApiManager.getJobResponseDtos();
        return new ListItemReader<>(jobResponseDtos);
    }

    @Bean
    @StepScope
    public JobProcess process() {
        return new JobProcess();
    }

    @Bean
    @StepScope
    public ItemWriter<JobResponseDto> saraminWriter() {
        return dto -> dto.getItems().forEach(jobStatisticService::create);
    }

Untitled