Java Code Examples for org.springframework.batch.repeat.RepeatStatus#FINISHED

The following examples show how to use org.springframework.batch.repeat.RepeatStatus#FINISHED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HealthCheckTasklet.java    From pinpoint with Apache License 2.0 7 votes vote down vote up
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
    List<String> urlList = generatedFlinkManagerServerApi();

    if (urlList.isEmpty()) {
        return RepeatStatus.FINISHED;
    }

    Map<String, Boolean> jobExecuteStatus = createjobExecuteStatus();

    for (String url : urlList) {
        try {
            ResponseEntity<Map> responseEntity = this.restTemplate.exchange(url, HttpMethod.GET, null, Map.class);

            if (responseEntity.getStatusCode() != HttpStatus.OK) {
                continue;
            }

            checkJobExecuteStatus(responseEntity, jobExecuteStatus);
        } catch (Exception e) {
            logger.error("fail call api to flink server.", e);
        }
    }

    List<String> notExecuteJobList = new ArrayList<>(3);
    for (Map.Entry<String, Boolean> entry : jobExecuteStatus.entrySet()) {
        if (entry.getValue().equals(Boolean.FALSE)) {
            notExecuteJobList.add(entry.getKey());
        }
    }

    if (notExecuteJobList.size() > 0) {
        String exceptionMessage = String.format("job fail : %s", notExecuteJobList);
        throw new Exception(exceptionMessage);
    }

    return RepeatStatus.FINISHED;
}
 
Example 2
Source File: LinesReader.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
    Line line = fu.readLine();
    while (line != null) {
        lines.add(line);
        logger.debug("Read line: " + line.toString());
        line = fu.readLine();
    }
    return RepeatStatus.FINISHED;
}
 
Example 3
Source File: BaseTasklet.java    From seed with Apache License 2.0 5 votes vote down vote up
@Override
final public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
	this.stepContribution = stepContribution;
	this.chunkContext = chunkContext;
	// 画面传入参数取得
	Map<String, Object> jobParameters = chunkContext.getStepContext().getJobParameters();
	this.doExec(jobParameters);
	return RepeatStatus.FINISHED;
}
 
Example 4
Source File: StepService0005.java    From seed with Apache License 2.0 5 votes vote down vote up
private Tasklet nextBizDateTasklet(){
    return new Tasklet() {
        @Override
        public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) {
            //入参contribution=org.springframework.batch.core.StepContribution@153ef3fc[readCount=0,writeCount=0,filterCount=0,parentSkipCount=0,readSkipCount=0,writeSkipCount=0,processSkipCount=0,exitStatus=exitCode=EXECUTING;exitDescription=],chunkContext=org.springframework.batch.core.scope.context.ChunkContext@2313a648[stepContext=SynchronizedAttributeAccessor: [], stepExecutionContext={batch.taskletType=com.jadyer.seed.controller.batch.javaconfig.StepService0005$1, batch.stepType=org.springframework.batch.core.step.tasklet.TaskletStep}, jobExecutionContext={}, jobParameters={time=1536145118798},complete=false,attributes={}],chunkContext.getStepContext=org.springframework.batch.core.scope.context.StepContext@3441dec5[stepExecution=StepExecution: id=23, version=1, name=step0005, status=STARTED, exitStatus=EXECUTING, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=0, rollbackCount=0, exitDescription=,callbacks={},propertyContext=<null>,support=org.springframework.batch.repeat.context.SynchronizedAttributeAccessor$1@0]
            LogUtil.getLogger().info("入参contribution={},chunkContext={},chunkContext.getStepContext={}", ReflectionToStringBuilder.toString(contribution), ReflectionToStringBuilder.toString(chunkContext), ReflectionToStringBuilder.toString(chunkContext.getStepContext()));
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return RepeatStatus.FINISHED;
        }
    };
}
 
Example 5
Source File: LinesWriter.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
    for (Line line : lines) {
        fu.writeLine(line);
        logger.debug("Wrote line " + line.toString());
    }
    return RepeatStatus.FINISHED;
}
 
Example 6
Source File: CustomerReportJobConfig.java    From spring-batch-article with MIT License 5 votes vote down vote up
@Bean
public Tasklet tasklet() {
    return (contribution, chunkContext) -> {
        log.info("Executing tasklet step");
        return RepeatStatus.FINISHED;
    };
}
 
Example 7
Source File: CleanupTasklet.java    From spring-batch-performance-tuning with Apache License 2.0 5 votes vote down vote up
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
	for (String path : paths) {
		FileUtils.cleanDirectory(new File(path));
	}

	return RepeatStatus.FINISHED;
}
 
Example 8
Source File: HealthCheckTaskletV2.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
    List<String> urlList = generatedFlinkManagerServerApi();

    if (urlList.isEmpty()) {
        return RepeatStatus.FINISHED;
    }

    Map<String, Boolean> jobExecuteStatus = createjobExecuteStatus();

    for (String url : urlList) {
        try {
            ResponseEntity<Map> responseEntity = this.restTemplate.exchange(url, HttpMethod.GET, null, Map.class);

            if (responseEntity.getStatusCode() != HttpStatus.OK) {
                continue;
            }

            checkJobExecuteStatus(responseEntity, jobExecuteStatus);
        } catch (Exception e) {
            logger.error("fail call api to flink server.", e);
        }
    }

    List<String> notExecuteJobList = new ArrayList<>(3);
    for (Map.Entry<String, Boolean> entry : jobExecuteStatus.entrySet()) {
        if (entry.getValue().equals(Boolean.FALSE)) {
            notExecuteJobList.add(entry.getKey());
        }
    }

    if (notExecuteJobList.size() > 0) {
        String exceptionMessage = String.format("job fail : %s", notExecuteJobList);
        throw new Exception(exceptionMessage);
    }

    return RepeatStatus.FINISHED;
}
 
Example 9
Source File: JobConfiguration.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Bean
@StepScope
public Tasklet workerTasklet(
	final @Value("#{stepExecutionContext['partitionNumber']}") Integer partitionNumber) {

	return new Tasklet() {
		@Override
		public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
			System.out.println("This tasklet ran partition: " + partitionNumber);

			return RepeatStatus.FINISHED;
		}
	};
}
 
Example 10
Source File: TaskJobLauncherCommandLineRunnerCoreTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
	this.jobs = new JobBuilderFactory(this.jobRepository);
	this.steps = new StepBuilderFactory(this.jobRepository, this.transactionManager);
	Tasklet tasklet = (contribution, chunkContext) -> RepeatStatus.FINISHED;
	this.step = this.steps.get("step").tasklet(tasklet).build();
	this.job = this.jobs.get("job").start(this.step).build();
	this.runner = new TaskJobLauncherCommandLineRunner(this.jobLauncher,
			this.jobExplorer, this.jobRepository, new TaskBatchProperties());

}
 
Example 11
Source File: CampusCourseCreatorTasklet.java    From olat with Apache License 2.0 5 votes vote down vote up
@Override
public RepeatStatus execute(StepContribution arg0, ChunkContext arg1) throws Exception {
    LOG.info("Methode execute started...");
    createAllCampusCoursesFromTemplate();
    LOG.info("Methode execute finished.");
    return RepeatStatus.FINISHED;
}
 
Example 12
Source File: LinesProcessor.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
    for (Line line : lines) {
        long age = ChronoUnit.YEARS.between(line.getDob(), LocalDate.now());
        logger.debug("Calculated age " + age + " for line " + line.toString());
        line.setAge(age);
    }
    return RepeatStatus.FINISHED;
}
 
Example 13
Source File: CleanupTasklet.java    From spring-batch-performance-tuning with Apache License 2.0 4 votes vote down vote up
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
	FileUtils.cleanDirectory(new File(processedImagePath));

	return RepeatStatus.FINISHED;
}
 
Example 14
Source File: CleanupTasklet.java    From spring-batch-performance-tuning with Apache License 2.0 4 votes vote down vote up
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
	FileUtils.cleanDirectory(new File(processedImagePath));

	return RepeatStatus.FINISHED;
}
 
Example 15
Source File: CleanupTasklet.java    From spring-batch-performance-tuning with Apache License 2.0 4 votes vote down vote up
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
	FileUtils.cleanDirectory(new File(processedImagePath));

	return RepeatStatus.FINISHED;
}
 
Example 16
Source File: CleanupTasklet.java    From spring-batch-performance-tuning with Apache License 2.0 4 votes vote down vote up
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
	FileUtils.cleanDirectory(new File(processedImagePath));

	return RepeatStatus.FINISHED;
}
 
Example 17
Source File: NoopTasklet.java    From spring-batch-performance-tuning with Apache License 2.0 4 votes vote down vote up
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
	return RepeatStatus.FINISHED;
}
 
Example 18
Source File: BaseTasklet.java    From spring-boot-doma2-sample with Apache License 2.0 4 votes vote down vote up
/**
 * メインメソッド
 * 
 * @param contribution
 * @param chunkContext
 * @return
 * @throws Exception
 */
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws IOException {
    val itemValidator = getValidator();
    val context = BatchContextHolder.getContext();

    val springValidator = new SpringValidator<I>();
    springValidator.setValidator(itemValidator);

    // 処理対象を読み込む
    val streams = doRead(context);

    for (int i = 0; i < streams.size(); i++) {
        try (val stream = streams.get(i)) {
            int[] idx = { 1 };

            stream.forEach(item -> {
                // 最初・最後のフラグを立てる
                setItemPosition(item, idx[0]);

                // 対象件数を加算する
                increaseTotalCount(context, item);

                val binder = new DataBinder(item);
                binder.addValidators(beanValidator, itemValidator);
                binder.validate();

                val br = binder.getBindingResult();
                if (br.hasErrors()) {
                    // エラー件数をカウントする
                    increaseErrorCount(context, br, item);

                    // バリデーションエラーがある場合
                    onValidationError(context, br, item);
                }

                if (!br.hasErrors()) {
                    // 実処理
                    doProcess(context, item);

                    // 処理件数をカウントする
                    increaseProcessCount(context, item);
                }

                idx[0]++;
            });
        }
    }

    return RepeatStatus.FINISHED;
}
 
Example 19
Source File: TaskLauncherTasklet.java    From composed-task-runner with Apache License 2.0 4 votes vote down vote up
/**
 * Executes the task as specified by the taskName with the associated
 * properties and arguments.
 *
 * @param contribution mutable state to be passed back to update the current step execution
 * @param chunkContext contains the task-execution-id used by the listener.
 * @return Repeat status of FINISHED.
 */
@Override
public RepeatStatus execute(StepContribution contribution,
		ChunkContext chunkContext) {
	if (this.executionId == null) {
		this.timeout = System.currentTimeMillis() +
				this.composedTaskProperties.getMaxWaitTime();
		logger.debug("Wait time for this task to complete is " +
				this.composedTaskProperties.getMaxWaitTime());
		logger.debug("Interval check time for this task to complete is " +
				this.composedTaskProperties.getIntervalTimeBetweenChecks());

		String tmpTaskName = this.taskName.substring(0,
				this.taskName.lastIndexOf('_'));

		List<String> args = this.arguments;

		ExecutionContext stepExecutionContext = chunkContext.getStepContext().getStepExecution().
				getExecutionContext();
		if (stepExecutionContext.containsKey("task-arguments")) {
			args = (List<String>) stepExecutionContext.get("task-arguments");
		}
		if(this.taskProperties.getExecutionid() != null) {
			args.add("--spring.cloud.task.parent-execution-id=" + this.taskProperties.getExecutionid());
		}
		this.executionId = this.taskOperations.launch(tmpTaskName,
				this.properties, args, null);

		stepExecutionContext.put("task-execution-id", executionId);
		stepExecutionContext.put("task-arguments", args);
	}
	else {
		try {
			Thread.sleep(this.composedTaskProperties.getIntervalTimeBetweenChecks());
		}
		catch (InterruptedException e) {
			Thread.currentThread().interrupt();
			throw new IllegalStateException(e.getMessage(), e);
		}

		TaskExecution taskExecution =
				this.taskExplorer.getTaskExecution(this.executionId);
		if (taskExecution != null && taskExecution.getEndTime() != null) {
			if (taskExecution.getExitCode() == null) {
				throw new UnexpectedJobExecutionException("Task returned a null exit code.");
			}
			else if (taskExecution.getExitCode() != 0) {
				throw new UnexpectedJobExecutionException("Task returned a non zero exit code.");
			}
			else {
				return RepeatStatus.FINISHED;
			}
		}
		if (this.composedTaskProperties.getMaxWaitTime() > 0 &&
				System.currentTimeMillis() > timeout) {
			throw new TaskExecutionTimeoutException(String.format(
					"Timeout occurred while processing task with Execution Id %s",
					this.executionId));
		}
	}
	return RepeatStatus.CONTINUABLE;
}
 
Example 20
Source File: BatchConfig.java    From Spring-5.0-Cookbook with MIT License 4 votes vote down vote up
@Bean
public Tasklet tasklet() {
    return (contrib, chunkCtx) -> {
        return RepeatStatus.FINISHED;
    };
}