-
Notifications
You must be signed in to change notification settings - Fork 152
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
Use Spring Boot ApplicationReadyEvent to start workers #1837
Comments
Users no longer need to invoke .start() on SpringApplication. Fixes temporalio#1837
Looking at this issue on the Spring Boot github spring-projects/spring-boot#35936 I think your right that the current approach is not correct. Is
Can you point me towards the docs that suggest this? |
I suggested One example in spring-boot that uses
In the docs for ApplicationReadyEvent There is also a comment in spring-boot#33935: I ran an empty
Whether |
My concern with ApplicationReadyEvent is this part
Since workers service requests I believe they should be started before this event. Looking at the spring integration with http servers, like tomcat, it looks like they don't listen for either of these events, they just assume people will use sprint bean lifecycles to make sure there beans start before the server if there is a dependency. Perhaps temporal workers autostart should work the same. |
There's upsides and downsides to invoking The upside is that it's fail-fast and the application will quit if on connection failure. The downside is that there are cases where I want the web servlet to start up even when temporal connection fails. The main one is the If the application aborts at startup then that I have to dig through the logs instead of using the health endpoint to see what's going wrong. Additionally, external monitoring tools expect to have a health check endpoint. A good connection at startup could always enter a bad state later. So if you were to go that route, I'd make aborting a configuration option, something like
Regardless of the decisions in this ticket, adding a HealthIndicator to this repo would be helpful. I couldn't deduce why there's a deferred startup, the Starter goes all the way back to the initial project commit. If the goal was to delay start to allow external configurations, the code could be modified to like WebMvcConfigurer. Something like: WorkerFactory createWorkerFactory(Collection<WorkerFactoryConfigurer> configurer) {
WorkerFactory workerFactory = ...; // existing codebase
// Apply custom configuration
for (var c : configurer) {
c.doConfig(workerFactory);
}
// Start factory, no more configuration.
try {
workerFactaory.start();
} catch (Exception e) {
if (!config.continueOnFailure) {
throw e;
}
LOG.warn("Failed to start temporal", e);
}
return workerFactory;
} Sorry for the long post if you were simply debating |
No I appreciate the long response. I was debating Yeah adding some sort of |
True, the event system is kind of a kludge; there's an implicit bound. But with current spring-boot library deferring WorkerFactory factory = WorkerFactory.newInstance(client);
Worker yourWorker = factory.newWorker("your_task_queue");
// Register Workflow
// and/or register Activities
factory.start(); with @Configuration
public class CustomWorkerConfig {
@AutoWired
FactoryWorker factoryWorker;
@PostConstruct
void addMyWorker() {
var worker = factoryWorker.newWorker("other_task_queue");
// Register Workflow
// and/or register Activities
}
} I needed this capability because I am implementing the host specific task queue like in the File Processing example. If the WorkerFactory is started at the time it becomes a bean, then the above wouldn't work. I'm unsure if there is a lifecycle phase that can call (Also, I opened #1839 about health indicators.) |
Is your feature request related to a problem? Please describe.
Hi there 👋!
After #1614, users must put
applicationContext.start()
in unit tests and main methods. Invokingstart()
is not idiomatic Spring Boot and leads to confusion when workers haven't started. (#1648). Even Spring Boot's Sample Application does not usestart()
Describe the solution you'd like
Use Spring Boot's
ApplicationReadyEvent
instead of Spring'sContextStartedEvent
.As described in Application Events and Listeners, An ApplicationReadyEvent is sent after any application and command-line runners have been called.
This represents the same application state as when
SpringApplication.run()
has returned and where users are instructed to manually add a callstart()
.Additionally, using
ApplicationReadyEvent
removes the need for every test to contain the boilerplateDescribe alternatives you've considered
.start()
and emit a warning.Additional context
I have a PR ready to submit if the feature is approved.
The text was updated successfully, but these errors were encountered: