-
-
Notifications
You must be signed in to change notification settings - Fork 67
Better management of Ebean Shutdown on SIGTERM #475
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,6 @@ | |
| import java.nio.file.Files; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import javax.inject.Inject; | ||
| import javax.inject.Singleton; | ||
| import play.Environment; | ||
|
|
@@ -34,21 +33,27 @@ public class EbeanDynamicEvolutions extends DynamicEvolutions { | |
|
|
||
| private final Map<String, Database> databases = new HashMap<>(); | ||
|
|
||
| @Inject | ||
| /** | ||
| * @deprecated No need to pass lifecycle anymore as shutdown is now managed by {@link | ||
| * play.db.ebean.EbeanLifecycle}. Use {@link #EbeanDynamicEvolutions(EbeanConfig, Environment, | ||
| * EvolutionsConfig)} instead. | ||
| */ | ||
| @Deprecated | ||
| public EbeanDynamicEvolutions( | ||
| EbeanConfig config, | ||
| Environment environment, | ||
| ApplicationLifecycle lifecycle, | ||
| EvolutionsConfig evolutionsConfig) { | ||
| this(config, environment, evolutionsConfig); | ||
| } | ||
|
|
||
| @Inject | ||
| public EbeanDynamicEvolutions( | ||
| EbeanConfig config, Environment environment, EvolutionsConfig evolutionsConfig) { | ||
| this.config = config; | ||
| this.environment = environment; | ||
| this.evolutionsConfig = evolutionsConfig; | ||
| start(); | ||
| lifecycle.addStopHook( | ||
| () -> { | ||
| databases.forEach((key, database) -> database.shutdown(false, false)); | ||
| return CompletableFuture.completedFuture(null); | ||
| }); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you actually not just replace this code with the code you added in
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @mkurz , Do you want us to change the code in-place and delete |
||
| } | ||
|
|
||
| /** Initialise the Ebean servers/databases. */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com> | ||
| */ | ||
|
|
||
| package play.db.ebean; | ||
|
|
||
| import io.ebean.event.ShutdownManager; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import javax.inject.Inject; | ||
| import javax.inject.Singleton; | ||
| import play.api.db.evolutions.DynamicEvolutions; | ||
| import play.inject.ApplicationLifecycle; | ||
|
|
||
| /** A Play module that automatically manages Ebean configuration. */ | ||
| @Singleton | ||
| public class EbeanLifecycle extends DynamicEvolutions { | ||
| @Inject | ||
| public EbeanLifecycle(ApplicationLifecycle lifecycle) { | ||
| ShutdownManager.deregisterShutdownHook(); | ||
| lifecycle.addStopHook( | ||
| () -> { | ||
| ShutdownManager.shutdown(); | ||
| return CompletableFuture.completedFuture(null); | ||
| }); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.