I have a Spring Cloud Task application setup to use spring.cloud.task.single-instance-enabled=true. When using this option, a lock record is created in the TASK_LOCK repository table and my task completes successfully. This lock record remains even though the task completed. Subsequent runs fail with "Failed to process @BeforeTask or @AfterTask annotation because: Task with name "application-1" is already running."
I've tried changing the parameters to make the task run unique but this did not work. If I specify a new task name, I can get it to run once but not twice. Removing the task lock record manually on the back-end will allow subsequent executions for the same task name.
Am I correct to assume that the task lock should be removed from the table upon completion of the task?
application.yml
spring:
cloud:
task:
single-instance-enabled: true
datasource:
url: ****
username: ****
password: ****
driver-class-name: oracle.jdbc.OracleDriver
jpa:
hibernate:
ddl-auto: create-drop
properties:
hibernate:
dialect: org.hibernate.dialect.Oracle12cDialect
Data Source Configurer class
import javax.sql.DataSource;
import org.springframework.cloud.task.configuration.DefaultTaskConfigurer;
public class DataSourceConfigurer extends DefaultTaskConfigurer {
public DataSourceConfigurer(DataSource dataSource)
{
super(dataSource);
}
}
Main Application class
. . .
@Autowired
private DataSource dataSource;
@Bean
public DataSourceConfigurer getTaskConfigurer() {
return new DataSourceConfigurer(dataSource);
}
. . .
I'm expecting the execution of a task with a given task name may only run at one time (in a running state). Once that task is completed, a task with the same name would be allowed to run.
The actual results are showing only one execution of a task with a given task name may run only one time. Task lock record remains and does not allow subsequent task executions even though the first run is complete.