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
Add IsRestarting property to Umbraco application notifications #11883
Add IsRestarting property to Umbraco application notifications #11883
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it makes sense, we can even move the IsRestarting
property to an interface and/or base class:
public interface IUmbracoApplicationLifetimeNotification : INotification
{
bool IsRestarting { get; }
}
public abstract class UmbracoApplicationLifetimeNotificationBase : IUmbracoApplicationLifetimeNotification
{
public UmbracoApplicationLifetimeNotificationBase(bool isRestarting = false) => IsRestarting = isRestarting;
public bool IsRestarting { get; }
}
I'm a bit undecided on this, as it adds some inheritance/complexity, but removes some duplication (including XML docs).
src/Umbraco.Core/Notifications/UmbracoApplicationStartedNotification.cs
Outdated
Show resolved
Hide resolved
src/Umbraco.Core/Notifications/UmbracoApplicationStoppedNotification.cs
Outdated
Show resolved
Hide resolved
After having another look, adding an I've also updated the constructors of the notifications, so you need to explicitly pass in a value for this property. I've only left the original constructors for the existing The new interface also allows the public class UmbracoApplicationNotificationHandler : INotificationHandler<UmbracoApplicationStartingNotification>, INotificationHandler<UmbracoApplicationStartedNotification>, INotificationHandler<UmbracoApplicationStoppingNotification>, INotificationHandler<UmbracoApplicationStoppedNotification>
{
private readonly ILogger _logger;
public UmbracoApplicationNotificationHandler(ILogger<UmbracoApplicationNotificationHandler> logger) => _logger = logger;
public void Handle(UmbracoApplicationStartingNotification notification) => Log(notification);
public void Handle(UmbracoApplicationStartedNotification notification) => Log(notification);
public void Handle(UmbracoApplicationStoppingNotification notification) => Log(notification);
public void Handle(UmbracoApplicationStoppedNotification notification) => Log(notification);
private void Log(IUmbracoApplicationLifetimeNotification notification) => _logger.LogInformation("{Type} - {IsRestarting}", notification.GetType().Name, notification.IsRestarting);
} |
* Add IsRestarting property to Umbraco application notifications * Add IUmbracoApplicationLifetimeNotification and update constructors * Only subscribe to events on initial startup * Cleanup CoreRuntime * Do not reset StaticApplicationLogging instance after stopping/during restart
Cherry picked to 9.3rc |
Prerequisites
Description
This is a minor addition to PR #11857 that adds a very useful
IsRestarting
property to theUmbracoApplicationStartingNotification
,UmbracoApplicationStartedNotification
,UmbracoApplicationStoppingNotification
andUmbracoApplicationStoppedNotification
.In 'normal' applications the running process is killed when it's stopped (and the application state is clean when started again), but that's not the case when Umbraco restarts: it's only stopping and starting the runtime, not the whole application.
So if you only want to execute some code on the initial startup of Umbraco, handling the
UmbracoApplicationStartingNotification
could result in running it twice when Umbraco has installed or upgraded (as that's when the Umbraco runtime gets restarted). In hindsight, we should've probably named theseUmbracoRuntime...Notification
instead 🤡Testing can be done using the same steps as described in the related PR, but you can replace the
UmbracoApplicationNotificationHandler
with the class below to log the value of the new property: