Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task observability interferes with task execution listener implementations that also implement the ApplicationRunner interface #936

Closed
ferdinandhuebner opened this issue Nov 17, 2023 · 2 comments

Comments

@ferdinandhuebner
Copy link

What happened?

Some of our projects implemented a task execution listener by annotating methods with @BeforeTask and @AfterTask. That task execution listener also implemented the ApplicationRunner interface to run the actual task.

Task observability was turned on with the spring.cloud.task.observation.enabled=true configuration property.

ObservationApplicationRunnerBeanPostProcessor discovers our ApplicationRunner implementation and wraps it into an ObservationApplicationRunner. As a result, the task execution listener plumbing in TaskLifecycleConfiguration and/or TaskLifecycleListener no longer detects the class as a task execution listener and the methods annotated with @BeforeTask and @AfterTask are no longer executed.

What did you expect to happen?

A class that implements ApplicationRunner should also be able to implement the TaskExecutionListener interface or annotate methods with the @BeforeTask, @AfterTask or @FailedTask without change in behaviour if task observability is turned on.

How can we reproduce it?

Please find a reproducer here: ferdinandhuebner/spring-cloud-task-listener-executor-bug:

Anything else we need to know?

  • Spring Cloud version: 2022.0.4
  • Spring Cloud Task version: 3.0.3
  • Spring Boot version: 3.1.5
@cppwfs
Copy link
Collaborator

cppwfs commented Dec 18, 2023

I'm so sorry for the delayed response.
To resolve your issue you need to update the signature of your @before task method from

  @BeforeTask
  public void beforeTask(TaskExecution taskExecution) {
    LOG.info("beforeTask was called");
    beforeTaskWasExecuted.set(true);
    executionId = taskExecution.getExecutionId();
  }

to

@BeforeTask
public TaskExecution beforeTask(TaskExecution taskExecution) {
  LOG.info("beforeTask was called");
  beforeTaskWasExecuted.set(true);
  executionId = taskExecution.getExecutionId();
  return taskExecution;
}

@cppwfs
Copy link
Collaborator

cppwfs commented Jan 2, 2024

I'm closing this issue as resolved. If you think this was closed in error, please add a comment. Thanks

@cppwfs cppwfs closed this as completed Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants