1

我正在从普通的 Spring Batch 迁移到 Spring Cloud 任务,并通过 Spring Cloud 数据流执行 Spring Batch。我在我的工作和为文件注入部署的示例工作中都遇到了以下问题:

https://docs.spring.io/spring-cloud-dataflow-samples/docs/current/reference/htmlsingle/#_batch_file_ingest

我正在使用带有 postgres 后端的 spring-cloud-dataflow-server-local-1.4.0.RELEASE。我还修改了该示例以使用 postgres 数据库。

当我尝试使用不同的参数第二次运行任务时,就会出现问题。当我第一次运行它时:

task launch fileInjectTask --arguments "filePath=classpath:data.csv --spring.cloud.task.closecontext_enable=false"

以下是日志中的输出:

2018-03-22 10:10:51.446 INFO 10431 --- [main] osbabJobLauncherCommandLineRunner:运行默认命令行:[filePath=classpath:data.csv,--spring.cloud.task.closecontext_enable=false,--spring .cloud.task.executionid=13]

2018-03-22 10:10:51.497 INFO 10431 --- [main] osbclsupport.SimpleJobLauncher:作业:[FlowJob:[name=ingestJob]] 使用以下参数启动:[{filePath=classpath:data.csv,- spring.cloud.task.executionid=13,-spring.cloud.task.closecontext_enable=false,run.id=1}]

没关系,参数被传递给批处理作业。现在,当我尝试使用不同的任务参数运行相同的任务时:

task launch fileInjectTask --arguments "filePath=/home/hmcmanus/spring-cloud-dataflow-samples/batch/file-ingest/src/main/resources/data.csv --spring.cloud.task.closecontext_enable=false"

我在日志中得到以下信息:

2018-03-22 10:12:18.249 INFO 10554 --- [main] osbabJobLauncherCommandLineRunner:运行默认命令行:[filePath=/home/hmcmanus/spring-cloud-dataflow-samples/batch/file-ingest/src/主/资源/data.csv,--spring.cloud.task.closecontext_enable=false,--spring.cloud.task.executionid=14]

2018-03-22 10:12:18.322 INFO 10554 --- [main] osbclsupport.SimpleJobLauncher:作业:[FlowJob:[name=ingestJob]] 使用以下参数启动:[{filePath=classpath:data.csv,- spring.cloud.task.executionid=13,run.id=1,-spring.cloud.task.closecontext_enable=false}]

正如您在第二个示例中看到的,任务的参数很好,但是批处理作业的参数是任务执行的旧参数。

有什么我在这里想念的吗?为什么spring批处理作业获取不到新任务执行的参数?

更新

为了排除数据库中的差异以及我需要进行的任何修改以使其运行,我还验证了与数据流服务器和任务的嵌入式 H2 数据库相同的功能。

4

1 回答 1

0

我在那个例子中遇到了同样的情况。到目前为止,我已经意识到正在使用任务的第一次执行的 id 作为参数来执行作业,在您的情况下 task.executionid=13。此值不会随着作业执行而更改。根据 Spring Cloud 任务参考:

Spring Boot 为在 über-jar 中轻松执行批处理作业提供了便利。Spring Boot 对此功能的支持允许开发人员在该执行中执行多个批处理作业。Spring Cloud Task 提供了将作业的执行(作业执行)与任务的执行相关联的能力,以便可以追溯到另一​​个。

此功能是通过使用 TaskBatchExecutionListener 完成的。默认情况下,此侦听器在任何配置了 Spring Batch Job 的上下文中自动配置(通过在上下文中定义 Job 类型的 bean)并且 spring-cloud-task-batch jar 在类路径中可用。侦听器将被注入到所有作业中。

https://docs.spring.io/spring-cloud-task/current-SNAPSHOT/reference/htmlsingle/#batch-association

但是,在示例中,要求已按说明涵盖。

于 2018-03-22T02:08:03.947 回答