0
votes

I have deployed a Spring Batch project as a task on Spring Cloud Data Flow (Using @EnableTask).

I have used spring.cloud.task.singleInstanceEnabled=true to avoid relaunching task while task's status is still running on Spring Cloud Data Flow. This property is placed in application.properties of Spring Batch project. (following this link -- https://docs.spring.io/spring-cloud-task/docs/2.0.0.RELEASE/reference/htmlsingle/#_restricting_spring_cloud_task_instances)

However, the results are not as my expectation while testing:

1st time run: job A is launched successfully (about 15 minutes)

2nd time run: job A is launched again during 1st time run so it had the error:

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.

When I launch the job 2nd time the Spring Cloud Data Flow still show that Successfully launched task "A" but the log got error which I mentioned above.

And at the end, the status of Task is "ERROR" while the 1st time run is completed. ( I think the status should be COMPLETE because the job 1st time)

How can I restrict Spring Cloud Task Instances correctly?

1

1 Answers

1
votes

The task instance restriction is a feature of Spring Cloud Task (your applications), not Spring Cloud Data Flow. Because of this, what you are seeing is expected behavior. You can open up an issue with the Spring Cloud Data Flow project for us to discuss adding that feature at the Spring Cloud Data Flow level.