[英]spring batch : how to dynamically create steps and tasks
I am a spring newbie and a spring batch newbie -- so, please bear with me.我是spring新手和spring批量新手——所以,请多多包涵。
I understand that spring batch is the framework that will help run steps and tasks.我知道 spring 批处理是有助于运行步骤和任务的框架。
I tried using spring batch by creating steps and task using but these steps and tasks are hardcoded at program build/compile time.我尝试通过使用创建步骤和任务来使用 spring 批处理,但这些步骤和任务在程序构建/编译时被硬编码。 However, I could not figure out how to dynamically create Tasks and Steps.
但是,我不知道如何动态创建任务和步骤。
What I want to do is to have a user create a script of how tasks are assembled from a list of steps.我想要做的是让用户创建一个脚本,说明如何从步骤列表中组装任务。 Each step will invoke a remote call to an existing REST endpoint.
每个步骤都会调用对现有 REST 端点的远程调用。 A task will have multiple such steps.
一个任务会有多个这样的步骤。 the user will create multiple such tasks.
用户将创建多个这样的任务。
Is it possible to dynamically create such a task with such steps?是否可以通过这样的步骤动态创建这样的任务? If yes, could you point me to some sample code how to do this with the required API?
如果是,您能否指出一些示例代码如何使用所需的 API 执行此操作?
UPDATE:更新:
I understand that a HelloWorld Job which calls a REST application using callRestApplication() looks like this.我知道使用 callRestApplication() 调用 REST 应用程序的 HelloWorld Job 看起来像这样。
@SpringBootApplication
@EnableBatchProcessing
public class HelloApplication {
@Autowired
private JobBuilderFactory jobBuilderFactory;
@Autowired
private StepBuilderFactory stepBuilderFactory;
@Bean
public Step step() {
return this.stepBuilderFactory.get("step1")
.tasklet((stepContribution, chunkContext) -> {
callRestApplication();
return RepeatStatus.FINISHED;
}).build();
}
@Bean
public Job job() {
return this.jobBuilderFactory.get("HelloWorldJob")
.start(step())
.build();
}
public static void main(String[] args) {
SpringApplication.run(HelloApplication.class, args);
}
}
However, this is static. I was looking for a way where I can do something like this然而,这是 static。我一直在寻找一种方法来做这样的事情
public static void main(String[] args) {
SpringApplication.run(HelloagainApplication.class, args);
List<JobDefinition> jobDefinitions = parseScript();
for (JobDefinition jobDefinition : jobDefinitions) {
Job job = new Job();
job.setName(jobDefinition.getName());
for (StepDefinition stepDefinition : jobDefinition.getStepDefinitions()) {
Step step = new Step();
step.setEndPoint(stepDefinition.getEndPoint());
step.setName(stepDefinition.getName());
step.setProperty1(stepDefinition.getProp1());
job.addStep(step);
}
job.startJob();
}
}
If the script has 10 job definitions, then 10 jobs will be started, each with x number of steps.如果脚本有 10 个作业定义,则将启动 10 个作业,每个作业有 x 个步骤。
In spring batch, how can I do the following在 spring 批次中,我该如何进行以下操作
Thanks谢谢
There is no such feature in Spring Batch. Spring批次中没有这个功能。 You need to write custom code that parses your user's script and create job/step definitions accordingly.
您需要编写自定义代码来解析用户的脚本并相应地创建作业/步骤定义。
That said, Spring Cloud Dataflow might help you.也就是说,Spring Cloud Dataflow 可能会对您有所帮助。 You can pre-define your tasks and let the user compose them using the GUI or the text-based scriptable DSL.
您可以预先定义您的任务,并让用户使用 GUI 或基于文本的可编写脚本的 DSL 来编写它们。 Another feature that could be interesting to you is the single-step job starter from Spring Cloud Task, which allows you to dynamically create a single-step job by providing some properties (no coding needed).
您可能感兴趣的另一个功能是来自 Spring Cloud Task 的单步作业启动器,它允许您通过提供一些属性(无需编码)动态创建单步作业。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.