aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/ApplicationHost.cs
diff options
context:
space:
mode:
authorJoshua M. Boniface <joshua@boniface.me>2019-02-03 22:23:54 -0500
committerGitHub <noreply@github.com>2019-02-03 22:23:54 -0500
commitc4f51e16a5ba093f32e8c87b8ccd49efc4a27757 (patch)
treeef797491c45d8eaafa3f8993836593bdc2e20983 /Emby.Server.Implementations/ApplicationHost.cs
parent56dcc45dc04de6be775551f14d1ad0bb235d72f9 (diff)
parent85a58fd655240fd0ddd10bdaaad4a9bb8cd7051d (diff)
Merge pull request #736 from Bond-009/startasync
Start startup tasks async
Diffstat (limited to 'Emby.Server.Implementations/ApplicationHost.cs')
-rw-r--r--Emby.Server.Implementations/ApplicationHost.cs35
1 files changed, 14 insertions, 21 deletions
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs
index a43faaa2e..365eb5856 100644
--- a/Emby.Server.Implementations/ApplicationHost.cs
+++ b/Emby.Server.Implementations/ApplicationHost.cs
@@ -645,8 +645,10 @@ namespace Emby.Server.Implementations
/// <summary>
/// Runs the startup tasks.
/// </summary>
- public Task RunStartupTasks()
+ public async Task RunStartupTasks()
{
+ Logger.LogInformation("Running startup tasks");
+
Resolve<ITaskManager>().AddTasks(GetExports<IScheduledTask>(false));
ConfigurationManager.ConfigurationUpdated += OnConfigurationUpdated;
@@ -665,20 +667,20 @@ namespace Emby.Server.Implementations
Logger.LogInformation("ServerId: {0}", SystemId);
var entryPoints = GetExports<IServerEntryPoint>();
- RunEntryPoints(entryPoints, true);
+
+ var now = DateTime.UtcNow;
+ await Task.WhenAll(StartEntryPoints(entryPoints, true));
+ Logger.LogInformation("Executed all pre-startup entry points in {Elapsed:fff} ms", DateTime.Now - now);
Logger.LogInformation("Core startup complete");
HttpServer.GlobalResponse = null;
- Logger.LogInformation("Post-init migrations complete");
-
- RunEntryPoints(entryPoints, false);
- Logger.LogInformation("All entry points have started");
-
- return Task.CompletedTask;
+ now = DateTime.UtcNow;
+ await Task.WhenAll(StartEntryPoints(entryPoints, false));
+ Logger.LogInformation("Executed all post-startup entry points in {Elapsed:fff} ms", DateTime.Now - now);
}
- private void RunEntryPoints(IEnumerable<IServerEntryPoint> entryPoints, bool isBeforeStartup)
+ private IEnumerable<Task> StartEntryPoints(IEnumerable<IServerEntryPoint> entryPoints, bool isBeforeStartup)
{
foreach (var entryPoint in entryPoints)
{
@@ -687,18 +689,9 @@ namespace Emby.Server.Implementations
continue;
}
- var name = entryPoint.GetType().FullName;
- Logger.LogInformation("Starting entry point {Name}", name);
- var now = DateTime.UtcNow;
- try
- {
- entryPoint.Run();
- }
- catch (Exception ex)
- {
- Logger.LogError(ex, "Error while running entrypoint {Name}", name);
- }
- Logger.LogInformation("Entry point completed: {Name}. Duration: {Duration} seconds", name, (DateTime.UtcNow - now).TotalSeconds.ToString(CultureInfo.InvariantCulture), "ImageInfos");
+ Logger.LogDebug("Starting entry point {Type}", entryPoint.GetType());
+
+ yield return entryPoint.RunAsync();
}
}