限制Spring Cloud Data Flow上的并发任务执行

我已经在Spring Cloud Data Flow上部署了一个Spring Batch项目作为任务(使用@Enabletask)。

我已使用spring.cloud.task.singleInstanceEnabled=true来避免在Spring Cloud Data Flow上仍在运行任务状态时重新启动任务。该属性放置在Spring Batch项目的application.properties中。 (跟随此链接-https://docs.spring.io/spring-cloud-task/docs/2.0.0.RELEASE/reference/htmlsingle/#_restricting_spring_cloud_task_instances

但是,测试时的结果并不符合我的预期:

第一次运行:作业A成功启动(大约15分钟)

第二次运行:作业A在第一次运行期间再次启动,因此出现错误:

ERROR o.s.c.t.l.TaskLifecycleListener - org.springframework.cloud.task.listener.TaskExecutionException: Failed to process @Beforetask or @AfterTask annotation because: Task with name "A" is already running.
ERROR o.s.c.t.l.TaskLifecycleListener - An event to end a task has been received for a task that has not yet started.
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
...
Caused by: org.springframework.cloud.task.listener.TaskExecutionException: Failed to process @Beforetask or @AfterTask annotation because: Task with name "A" is already running.
...
Caused by: java.lang.reflect.invocationTargetException: null
...
Caused by: org.springframework.cloud.task.listener.TaskExecutionException: Task with name "A" is already running.

当我第二次启动作业时,Spring Cloud Data Flow仍然显示成功启动任务“ A”,但是日志出现了我上面提到的错误。

最后,第一次运行完成时,任务的状态为“错误”。 (我认为状态应该是COMPLETE,因为工作是第一次)

如何正确限制Spring Cloud Task实例?

qizheyu2009 回答:限制Spring Cloud Data Flow上的并发任务执行

任务实例限制是Spring Cloud Task(您的应用程序)的功能,而不是Spring Cloud Data Flow的功能。因此,您看到的是预期的行为。您可以为Spring Cloud Data Flow项目打开一个问题,以供我们讨论在Spring Cloud Data Flow级别添加该功能。

本文链接:https://www.f2er.com/3118200.html

大家都在问