【问题标题】:Restricting concurrent task execution on Spring Cloud Data Flow限制 Spring Cloud Data Flow 上的并发任务执行
【发布时间】:2019-11-12 10:32:04
【问题描述】:

我已经在 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 数据流仍然显示成功启动任务“A”但日志出现我上面提到的错误。

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

如何正确限制 Spring Cloud 任务实例?

【问题讨论】:

    标签: spring spring-batch spring-cloud-dataflow spring-cloud-task


    【解决方案1】:

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

    【讨论】:

    • Spring Cloud Data Flow 有限制任务实例的功能吗?
    • Spring Cloud Data Flow (SCDF) 能够限制在给定空间/等中运行的总任务,但不能像这样在任务定义级别。如果您在 Github 上打开问题,我们可以查看添加该功能。
    • 1 年后,这是实施还是存在 WIP?谢谢
    猜你喜欢
    • 2020-09-07
    • 1970-01-01
    • 2019-06-28
    • 2018-01-24
    • 1970-01-01
    • 2017-04-04
    • 1970-01-01
    • 2018-02-06
    • 2020-10-15
    相关资源
    最近更新 更多