Java 类org.springframework.batch.core.JobParametersBuilder 实例源码
项目:nixmash-blog
文件:DemoJobRunner.java
@Scheduled(fixedDelayString = "${demo.job.fixed.delay.seconds:60}000")
public void runDemoJob() {
SimpleDateFormat format = new SimpleDateFormat("M-dd-yy hh:mm:ss");
String startDateTime = format.format(new Date());
JobParameters jobParameters =
new JobParametersBuilder()
.addLong("iterations", iterations)
.addString("username", username)
.addLong("time", System.currentTimeMillis()).toJobParameters();
try {
logger.info("");
logger.info("STARTING BATCH JOB AT " + startDateTime);
JobExecution execution = jobLauncher.run(demoJob, jobParameters);
logger.info("JOB STATUS : " + execution.getStatus());
} catch (Exception e) {
e.printStackTrace();
logger.info("JOB FAILED!!!");
}
}
项目:kowalski
文件:Application.java
public void start() throws IOException, InterruptedException {
List<JobExecution> jobExecutions = new ArrayList<>();
// launch jobs
jobExecutions.addAll(IntStream.range(0, this.cardinality).mapToObj(i -> {
Job analysisJob = this.jobFactory.get();
JobParametersBuilder jobParametersBuilder = new JobParametersBuilder();
jobParametersBuilder.addString("id", analysisJob.getName() + "-" + i, true);
try {
return this.jobLauncher.run(analysisJob, jobParametersBuilder.toJobParameters());
} catch (JobExecutionAlreadyRunningException | JobRestartException | JobInstanceAlreadyCompleteException
| JobParametersInvalidException exception) {
throw new RuntimeException(exception);
}
}).collect(Collectors.toList()));
// wait for termination
while (jobExecutions.stream().anyMatch(jobExecution -> jobExecution.getStatus().isRunning())) {
Thread.sleep(1000);
}
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot
文件:JobLauncherCommandLineRunnerTests.java
@Test
public void retryFailedExecutionWithNonIdentifyingParameters() throws Exception {
this.job = this.jobs.get("job")
.start(this.steps.get("step").tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution,
ChunkContext chunkContext) throws Exception {
throw new RuntimeException("Planned");
}
}).build()).incrementer(new RunIdIncrementer()).build();
JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false)
.addLong("foo", 2L, false).toJobParameters();
this.runner.execute(this.job, jobParameters);
this.runner.execute(this.job, jobParameters);
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
}
项目:spring-boot-concourse
文件:JobLauncherCommandLineRunnerTests.java
@Test
public void retryFailedExecutionWithNonIdentifyingParameters() throws Exception {
this.job = this.jobs.get("job")
.start(this.steps.get("step").tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution,
ChunkContext chunkContext) throws Exception {
throw new RuntimeException("Planned");
}
}).build()).incrementer(new RunIdIncrementer()).build();
JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false)
.addLong("foo", 2L, false).toJobParameters();
this.runner.execute(this.job, jobParameters);
this.runner.execute(this.job, jobParameters);
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
}
项目:Spring-Batch-en-Castellano
文件:Main.java
public static void main(String[] args) {
String[] springConfig = { "spring/batch/jobs/job-config.xml" };
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("multiResourceItemReaderJob");
try {
JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
JobExecution execution = jobLauncher.run(job, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
System.out.println("Exit Status : " + execution.getAllFailureExceptions());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
}
项目:Spring-Batch-en-Castellano
文件:Main.java
public static void main(String[] args) {
String[] springConfig = { "spring/batch/jobs/job-config.xml" };
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("customReaderWriterProcesorJob");
try {
JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
JobExecution execution = jobLauncher.run(job, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
System.out.println("Exit Status : " + execution.getAllFailureExceptions());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
}
项目:Spring-Batch-en-Castellano
文件:Main.java
public static void main(String[] args) {
String[] springConfig = { "spring/batch/jobs/job-config.xml" };
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("taskletJob");
try {
JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
JobExecution execution = jobLauncher.run(job, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
System.out.println("Exit Status : " + execution.getAllFailureExceptions());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
}
项目:Spring-Batch-en-Castellano
文件:Main.java
public static void main(String[] args) {
String[] springConfig = { "spring/batch/jobs/job-config.xml" };
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("customListeners");
try {
JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
JobExecution execution = jobLauncher.run(job, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
System.out.println("Exit Status : " + execution.getAllFailureExceptions());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
}
项目:Spring-Batch-en-Castellano
文件:Main.java
public static void main(String[] args) {
String[] springConfig = { "spring/batch/jobs/job-config.xml" };
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("flatFileItemWriterJob");
try {
JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
JobExecution execution = jobLauncher.run(job, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
System.out.println("Exit Status : " + execution.getAllFailureExceptions());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
}
项目:Spring-Batch-en-Castellano
文件:Main.java
public static void main(String[] args) {
String[] springConfig = { "spring/batch/jobs/job-config.xml" };
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("parallelStepsJob");
try {
JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
JobExecution execution = jobLauncher.run(job, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
System.out.println("Exit Status : " + execution.getAllFailureExceptions());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
}
项目:Spring-Batch-en-Castellano
文件:Main.java
public static void main(String[] args) {
String[] springConfig = { "spring/batch/jobs/job-config.xml" };
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("chunkJob");
try {
JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
JobExecution execution = jobLauncher.run(job, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
System.out.println("Exit Status : " + execution.getAllFailureExceptions());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
}
项目:Spring-Batch-en-Castellano
文件:Main.java
public static void main(String[] args) {
String[] springConfig = { "spring/batch/jobs/job-config.xml" };
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("secuentialControlFlow");
try {
JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
JobExecution execution = jobLauncher.run(job, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
System.out.println("Exit Status : " + execution.getAllFailureExceptions());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
}
项目:Spring-Batch-en-Castellano
文件:Main.java
public static void main(String[] args) {
String[] springConfig = { "spring/batch/jobs/job-config.xml" };
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("xmlReadersWritersJob");
try {
JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
JobExecution execution = jobLauncher.run(job, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
System.out.println("Exit Status : " + execution.getAllFailureExceptions());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
}
项目:Spring-Batch-en-Castellano
文件:Main.java
public static void main(String[] args) {
String[] springConfig = { "spring/batch/jobs/job-config.xml" };
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("taskletJob");
try {
JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
JobExecution execution = jobLauncher.run(job, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
System.out.println("Exit Status : " + execution.getAllFailureExceptions());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
}
项目:Camel
文件:SpringBatchProducer.java
/**
* Helper method converting the Camel message headers into the Spring Batch parameters map. Date, Long and Double
* header values are converted to the appropriate types. All the other header values are converted to string
* representation.
*
* @param headers Camel message header to be converted
* @return Camel message headers converted into the Spring Batch parameters map
*/
protected JobParameters prepareJobParameters(Map<String, Object> headers) {
JobParametersBuilder parametersBuilder = new JobParametersBuilder();
for (Map.Entry<String, Object> headerEntry : headers.entrySet()) {
String headerKey = headerEntry.getKey();
Object headerValue = headerEntry.getValue();
if (headerValue instanceof Date) {
parametersBuilder.addDate(headerKey, (Date) headerValue);
} else if (headerValue instanceof Long) {
parametersBuilder.addLong(headerKey, (Long) headerValue);
} else if (headerValue instanceof Double) {
parametersBuilder.addDouble(headerKey, (Double) headerValue);
} else if (headerValue != null) {
parametersBuilder.addString(headerKey, headerValue.toString());
} else {
// if the value is null we just put String with null value here to avoid the NPE
parametersBuilder.addString(headerKey, null);
}
}
JobParameters jobParameters = parametersBuilder.toJobParameters();
log.debug("Prepared parameters for Spring Batch job: {}", jobParameters);
return jobParameters;
}
项目:spring-boot-sandbox
文件:BatchLauncherController.java
@RequestMapping("/launch")
public String launch() throws JobExecutionAlreadyRunningException,
JobRestartException, JobInstanceAlreadyCompleteException,
JobParametersInvalidException {
//JobParametersの内容を変更しないと同一のジョブ実行と思われるっぽい。
//同一のジョブ実行だと思われたら二回目からは実行されない。
//(一回目の実行が既に完了しているので)
//とりあえずIDっぽいものを持たせて実行の要求の度にインクリメントすることで
//何度も実行できるようになった。
//cf. JobParametersIncrementer
JobParameters jobParameters = new JobParametersBuilder().addLong(
"simpleBatchId", idGenerator.getAndIncrement())
.toJobParameters();
JobExecution execution = launcher.run(job, jobParameters);
return execution.toString();
}
项目:building-microservices
文件:BatchConfiguration.java
CommandLineRunner runner(JobLauncher launcher,
Job job,
@Value("${file}") File in,
JdbcTemplate jdbcTemplate) {
return args -> {
JobExecution execution = launcher.run(job,
new JobParametersBuilder()
.addString("file", in.getAbsolutePath())
.toJobParameters());
System.out.println("execution status: " + execution.getExitStatus().toString());
List<Person> personList = jdbcTemplate.query("select * from PEOPLE", (resultSet, i) -> new Person(resultSet.getString("first"),
resultSet.getString("last"),
resultSet.getString("email")));
personList.forEach(System.out::println);
};
}
项目:contestparser
文件:JobLauncherCommandLineRunnerTests.java
@Test
public void retryFailedExecutionWithNonIdentifyingParameters() throws Exception {
this.job = this.jobs.get("job")
.start(this.steps.get("step").tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution,
ChunkContext chunkContext) throws Exception {
throw new RuntimeException("Planned");
}
}).build()).incrementer(new RunIdIncrementer()).build();
JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false)
.addLong("foo", 2L, false).toJobParameters();
this.runner.execute(this.job, jobParameters);
this.runner.execute(this.job, jobParameters);
assertEquals(1, this.jobExplorer.getJobInstances("job", 0, 100).size());
}
项目:GemFireLite
文件:ImportService.java
public void executeJob(String name, String tpl)
{
checkContextInitialized();
JobItem item = jobItems.get(name + tpl);
LogUtil.getAppLog().info("Job:" + name + " executing...");
try
{
JobExecution exec = jobLauncher.run(item.job, new JobParametersBuilder().addDate("StartTime", new Date())
.addString("name", name).toJobParameters());
String s1 = DateUtil.format(exec.getCreateTime(), "HH:mm:ss.SSS");
LogUtil.getAppLog().info("Job:" + name + " start asynchronous,start time:" + s1);
}
catch (Exception e)
{
LogUtil.getCoreLog().info("Job:" + name + " failed");
if (LogUtil.getCoreLog().isErrorEnabled())
LogUtil.getCoreLog().error(name, e);
}
}
项目:marklogic-spring-batch
文件:JobParametersAdapter.java
@Override
public JobParameters unmarshal(AdaptedJobParameters params) throws Exception {
JobParametersBuilder jobParametersBuilder = new JobParametersBuilder();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
for (AdaptedJobParameters.AdaptedJobParameter param : params.getParameters()) {
switch (param.type) {
case "STRING":
jobParametersBuilder.addString(param.key, param.value, param.identifier);
break;
case "DATE":
jobParametersBuilder.addDate(param.key, df.parse(param.value), param.identifier);
break;
case "DOUBLE":
jobParametersBuilder.addDouble(param.key, Double.valueOf(param.value), param.identifier);
break;
case "LONG":
jobParametersBuilder.addLong(param.key, Long.valueOf(param.value), param.identifier);
break;
}
}
return jobParametersBuilder.toJobParameters();
}
项目:marklogic-spring-batch
文件:JobParametersTestUtils.java
public static JobParameters getJobParameters() {
JobParametersBuilder jobParametersBuilder = new JobParametersBuilder();
if (jobParameters.isEmpty()) {
jobParametersBuilder.addLong("id", 1L, true);
jobParametersBuilder.addString("stringTest", "Joe Cool", true);
jobParametersBuilder.addDate("start", new Date(), false);
jobParametersBuilder.addLong("longTest", 1239L, false);
jobParametersBuilder.addDouble("doubleTest", 1.35D, false);
jobParameters = jobParametersBuilder.toJobParameters();
} else {
JobParametersTestUtils utils = new JobParametersTestUtils();
jobParameters = utils.getNext(jobParameters);
}
return jobParameters;
}
项目:WebAPI
文件:ExampleApplicationWithJobService.java
@POST
@Produces(MediaType.APPLICATION_JSON)
public JobExecutionResource queueJob() throws Exception {
//Allow unique combinations of JobParameters to run in parallel. An empty JobParameters() would only allow a JobInstance to run at a time.
final JobParameters jobParameters = new JobParametersBuilder().addString("param", "parameter with 250 char limit")
.addLong("time", System.currentTimeMillis()).toJobParameters();
final List<Concept> concepts = new ArrayList<Concept>();
final Concept c1 = new Concept();
c1.conceptName = "c1";
final Concept c2 = new Concept();
c2.conceptName = "c2";
concepts.add(c1);
concepts.add(c2);
return this.jobTemplate.launchTasklet(EXAMPLE_JOB_NAME, EXAMPLE_STEP_NAME, new ExampleApplicationTasklet(concepts),
jobParameters);
}
项目:WebAPI
文件:CDMResultsService.java
@GET
@Path("{sourceKey}/warmCache")
@Produces(MediaType.APPLICATION_JSON)
public JobExecutionResource warmCache(@PathParam("sourceKey") final String sourceKey) {
ResultsCache resultsCache = new ResultsCache();
CDMResultsCache cache = resultsCache.getCache(sourceKey);
if (cache != null) {
return new JobExecutionResource();
}
Source source = getSourceRepository().findBySourceKey(sourceKey);
CDMResultsCacheTasklet tasklet = new CDMResultsCacheTasklet(this.getSourceJdbcTemplate(source), source);
JobParametersBuilder builder = new JobParametersBuilder();
builder.addString("jobName", "warming " + sourceKey + " cache ");
return this.jobTemplate.launchTasklet("warmCache", "warmCacheStep", tasklet, builder.toJobParameters());
}
项目:AGIA
文件:JobLauncherDetails.java
/**
* Copy parameters that are of the correct type over to
* {@link org.springframework.batch.core.launch.JobLauncher JobParameters},
* ignoring jobName.
*
* @return a JobParameters instance
*/
private JobParameters getJobParametersFromJobMap(Map<String, Object> jobDataMap, JobParameters sPreviousJobParameters) {
JobParametersBuilder builder = (sPreviousJobParameters != null) ? new JobParametersBuilder(sPreviousJobParameters) : new JobParametersBuilder();
for (Entry<String, Object> entry : jobDataMap.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (value instanceof String && !key.equals(JOB_NAME)) {
builder.addString(key, (String) value);
} else if (value instanceof Float || value instanceof Double) {
builder.addDouble(key, ((Number) value).doubleValue());
} else if (value instanceof Integer || value instanceof Long) {
builder.addLong(key, ((Number) value).longValue());
} else if (value instanceof Date) {
builder.addDate(key, (Date) value);
} else {
LOGGER.debug("JobDataMap contains values which are not job parameters (ignoring).");
}
}
return builder.toJobParameters();
}
项目:spring-batch-tools
文件:BatchJacksonModuleTest.java
@Test
public void jobParameters() throws Exception {
final Date date = new Date();
final JobParameters parameters = new JobParametersBuilder() //
.addString("stringName", "stringValue") //
.addLong("longName", 123L) //
.addDouble("doubleName", 123.456d, false) //
.addDate("dateName", date, false) //
.toJobParameters();
final String json = mapper.writeValueAsString(parameters);
final JobParameters read = mapper.readValue(json, JobParameters.class);
assertThat("parameters after serialization", read, hasProperty("parameters", allOf(//
hasEntry("stringName", new JobParameter("stringValue", true)), //
hasEntry("longName", new JobParameter(123L, true)), //
hasEntry("doubleName", new JobParameter(123.456d, false)), //
hasEntry("dateName", new JobParameter(date, false)) //
)));
}
项目:spring-batch-tools
文件:BatchOperatorImplTest.java
@Test
public void startWithCustomStringParametersWithPreviousParameters() throws Exception {
final JobInstance previousInstance = mock(JobInstance.class);
when(jobExplorer.getJobInstances(JOB_NAME, 0, 1)).thenReturn(Arrays.asList(previousInstance));
final JobParameters previousParams = new JobParameters();
final JobExecution previousExecution = mock(JobExecution.class);
when(previousExecution.getJobParameters()).thenReturn(previousParams);
when(jobExplorer.getJobExecutions(previousInstance)).thenReturn(Arrays.asList(previousExecution));
final JobParameters incremented = new JobParametersBuilder(params).addString("test", "test").toJobParameters();
when(jobParametersIncrementer.getNext(previousParams)).thenReturn(incremented);
final JobParameters expected = new JobParametersBuilder(incremented).addString("foo", "bar").addLong("answer", 42L, false)
.toJobParameters();
when(jobLauncher.run(job, expected)).thenReturn(execution);
final JobParameters parameters = new JobParametersBuilder().addString("foo", "bar").addLong("answer", 42L, false).toJobParameters();
final long executionId = batchOperator.start(JOB_NAME, parameters);
assertThat("job execution id", executionId, is(1L));
}
项目:batchers
文件:TaxCalculationStepITest.java
@Test
public void taxCalculationStep_generatesCorrectCalculation() throws Exception {
Employee employee = haveOneEmployee();
JobParameters jobParameters = new JobParametersBuilder()
.addLong("year", 2014L, true)
.addLong("month", 5L, true)
.toJobParameters();
JobExecution jobExecution = jobLauncherTestUtils.launchStep(EmployeeJobConfigSingleJvm.TAX_CALCULATION_STEP, jobParameters);
assertThat(jobExecution.getExitStatus()).isEqualTo(ExitStatus.COMPLETED);
List<TaxCalculation> byEmployee = taxCalculationRepository.findByEmployee(employee);
assertThat(byEmployee).hasSize(1);
TaxCalculation taxCalculation = byEmployee.get(0);
assertThat(taxCalculation.getEmployee().getId()).isEqualTo(employee.getId());
assertThat(taxCalculation.getYear()).isEqualTo(2014);
assertThat(taxCalculation.getMonth()).isEqualTo(5);
List<TaxCalculation> byYearAndMonth = taxCalculationRepository.find(2014, 5, 1L);
assertThat(byYearAndMonth).hasSize(1);
}
项目:spring-boot-starter-batch-web
文件:ProtocolListenerTest.java
@Test
public void createProtocol() throws Exception {
// Given
JobExecution jobExecution = new JobExecution(1L, new JobParametersBuilder().addString("test", "value").toJobParameters());
jobExecution.setJobInstance(new JobInstance(1L, "test-job"));
jobExecution.setCreateTime(new Date());
jobExecution.setStartTime(new Date());
jobExecution.setEndTime(new Date());
jobExecution.setExitStatus(new ExitStatus("COMPLETED_WITH_ERRORS", "This is a default exit message"));
jobExecution.getExecutionContext().put("jobCounter", 1);
StepExecution stepExecution = jobExecution.createStepExecution("test-step-1");
stepExecution.getExecutionContext().put("stepCounter", 1);
ProtocolListener protocolListener = new ProtocolListener();
// When
protocolListener.afterJob(jobExecution);
// Then
String output = this.outputCapture.toString();
assertThat(output, containsString("Protocol for test-job"));
assertThat(output, containsString("COMPLETED_WITH_ERRORS"));
}
项目:springone-hadoop
文件:BatchApp.java
public static void main(String[] args) throws Exception {
AbstractApplicationContext context =
new ClassPathXmlApplicationContext("classpath:/META-INF/spring/application-context.xml");
log.info("Batch TweetCount Application Running");
context.registerShutdownHook();
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
Job job = context.getBean(Job.class);
jobLauncher.run(
job,
new JobParametersBuilder()
.addString("mr.input", "/tweets/input")
.addString("mr.output", "/tweets/output")
.addString("localData", "data/nbatweets-small.txt")
.addDate("date", new Date()).toJobParameters());
context.close();
}
项目:SpringBatch--MultiThreaded
文件:App.java
public static void main( String[] args )
{
System.out.println( "Hello World!" );
try {
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("SIGSettleJob.xml");
final JobLauncher jobLauncher = (JobLauncher) applicationContext.getBean("jobLauncher");
final Job job = (Job) applicationContext.getBean("importProducts");
System.out.println("batch context running job " + job);
final JobExecution jobExecution = jobLauncher.run(job, new JobParametersBuilder()
.addLong("timestamp", System.currentTimeMillis())
.toJobParameters()
);
batchStatus = jobExecution.getStatus();
} catch (Exception e) {
System.out.println("Exception thrown in batch context" + e.getMessage());
throw new RuntimeException(e);
}
System.out.println("batch context finished running job: " + batchStatus);
}
项目:spring-batch-experiments
文件:ImportProductsByJavaConfigTest.java
@Test
public void importProducts() throws Exception {
int initial = jdbcTemplate.queryForObject("select count(1) from product", Integer.class);
JobParameters jobParameters =
new JobParametersBuilder()
.addString("inputResource", "/input/products.zip")
.addString("targetDirectory", "./target/importProductsBatchByJavaConfig/")
.addString("targetFile", "products.txt")
.addLong("timestamp", System.currentTimeMillis())
.toJobParameters();
jobLauncher.run(importProductsJob, jobParameters);
int nbOfNewProducts = 7;
int totalNumber = jdbcTemplate.queryForObject("select count(1) from product", Integer.class);
Assertions.assertThat(totalNumber - initial).isEqualTo(nbOfNewProducts);
}
项目:spring-batch-experiments
文件:ImportProductsTest.java
@Test
public void importProducts() throws Exception {
int initial = jdbcTemplate.queryForObject("select count(1) from product", Integer.class);
JobParameters jobParameters =
new JobParametersBuilder()
.addString("inputResource", "/input/products.zip")
.addString("targetDirectory", "./target/importProductsBatch/")
.addString("targetFile", "products.txt")
.addLong("timestamp", System.currentTimeMillis())
.toJobParameters();
jobLauncher.run(importProductsJob, jobParameters);
int nbOfNewProducts = 7;
int totalNumber = jdbcTemplate.queryForObject("select count(1) from product", Integer.class);
Assertions.assertThat(totalNumber - initial).isEqualTo(nbOfNewProducts);
}
项目:spring-batch-experiments
文件:JtaTest.java
@Test
@Ignore("applicationDataSource() 얻기를 실패했는데 어떻게 해야 하는지 잘 모르겠다.")
public void batchTablesAndApplicationTablesOnDifferentDb() throws Exception {
int initial = getProductCount();
JobParameters params =
new JobParametersBuilder()
.addString("inputResource", "classpath:kr/spring/batch/chapter09/jta/products.zip")
.addString("targetDirectory", ".target/importproductsbatch/")
.addString("targetFile", "products.txt")
.addLong("timestamp", System.currentTimeMillis())
.toJobParameters();
jobLauncher.run(job, params);
Assertions.assertThat(getProductCount()).isEqualTo(initial + 7);
}
项目:spring-batch-experiments
文件:SkipBehaviorTest.java
@Test
public void sunnyDay() throws Exception {
int read = 12;
configureServiceForRead(service, read);
JobExecution exec = jobLauncher.run(
job,
new JobParametersBuilder().addLong("time", System.currentTimeMillis())
.toJobParameters());
assertThat(exec.getStatus()).isEqualTo(BatchStatus.COMPLETED);
assertRead(read, exec);
assertWrite(read, exec);
assertReadSkip(0, exec);
assertProcessSkip(0, exec);
assertWriteSkip(0, exec);
assertCommit(3, exec);
assertRollback(0, exec);
}
项目:Spring-5.0-Cookbook
文件:BatchConfig.java
@Scheduled(fixedRate = 5000)
public void startJob() throws Exception {
JobExecution execution = jobLauncher.run(
deptBatchJob(),
new JobParametersBuilder().addLong("procId", System.nanoTime()).toJobParameters()
);
}
项目:Spring-5.0-Cookbook
文件:BatchConfig.java
@Scheduled(fixedRate = 5000)
public void startJob() throws Exception {
JobExecution execution = jobLauncher.run(
deptBatchJob(),
new JobParametersBuilder().addLong("procId", System.nanoTime()).toJobParameters()
);
}
项目:nixmash-blog
文件:GithubJobRunner.java
@Scheduled(fixedRateString = "${github.job.fixed.delay.seconds:60}000")
public void runGithubJob() {
SimpleDateFormat format = new SimpleDateFormat("M-dd-yy hh:mm:ss");
String startDateTime = format.format(new Date());
JobParameters jobParameters =
new JobParametersBuilder()
.addLong("time", System.currentTimeMillis()).toJobParameters();
try {
logger.info("");
logger.info("STARTING GITHUB BATCH JOB : " + startDateTime);
JobExecution execution = jobLauncher.run(githubJob, jobParameters);
logger.info("JOB STATUS : " + execution.getStatus());
} catch (Exception e) {
e.printStackTrace();
logger.info("JOB FAILED!!!");
}
}
项目:spring-batch-article
文件:CustomerReportJobConfig.java
@Scheduled(fixedRate = 5000)
public void run() throws Exception {
JobExecution execution = jobLauncher.run(
customerReportJob(),
new JobParametersBuilder().addLong("uniqueness", System.nanoTime()).toJobParameters()
);
log.info("Exit status: {}", execution.getStatus());
}
项目:appstatus-spring-boot-starter
文件:SampleController.java
/**
* Invoke job one.
*
* @return String
*/
@ResponseBody
@GetMapping("/invokejob")
public String invokejob() {
EXEC.execute(() -> {
try {
jobLauncher.run(oneJob, new JobParametersBuilder().toJobParameters());
} catch (JobExecutionException e) {
LOG.error("Error during job execution", e);
}
});
return "Batch job has been invoked";
}
项目:hub-fortify-ssc-integration-service
文件:BlackDuckFortifyJobConfig.java
/**
* Schedule the job and add it to the job launcher
*
* @throws Exception
*/
@Scheduled(cron = "${cron.expressions}")
public void execute() throws Exception {
JobParameters param = new JobParametersBuilder().addString("JobID",
String.valueOf(System.currentTimeMillis())).toJobParameters();
batchScheduler.jobLauncher().run(pushBlackDuckScanToFortifyJob(), param);
}