spring - 限制 Spring Cloud Data Flow 上的并发任务执行
问题描述
我已经部署了一个 Spring Batch 项目作为 Spring Cloud Data Flow (Using @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”,但日志出现我上面提到的错误。
最后,第一次运行完成时,Task 的状态为“ERROR”。(我认为状态应该是 COMPLETE 因为第一次工作)
如何正确限制 Spring Cloud 任务实例?
解决方案
任务实例限制是 Spring Cloud Task(您的应用程序)的功能,而不是 Spring Cloud Data Flow。因此,您看到的是预期行为。您可以打开 Spring Cloud Data Flow 项目的问题,让我们讨论在 Spring Cloud Data Flow 级别添加该功能。
推荐阅读
- powershell - 使用 csv 文件中的新名称重命名目录中的文件
- php - PHP:保存上次请求的 cookie 并在 GET 请求中使用它
- javascript - 有没有人有使用 @material-ui/pickers Calendar API 的经验?
- python - 相同的鼠标移动以不同的方式评估
- python - 在 Jupyter 中使用自定义 ContentsManager 创建新文件
- python - Python ASK 信号图
- artifactory - 无法使用 JFrog CLI 将文件上传到 Artifactory
- javascript - 在执行下一行代码之前等待几秒钟?
- html - 嵌入的 YouTube 视频在 iframe HTML 中不可用
- python - 如何使用 Django 查询嵌套的外键共享属性