-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
NEST-490: Setting loglevel to information
- Loading branch information
Showing
4 changed files
with
68 additions
and
25 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
Lombiq.Hosting.Tenants.IdleTenantManagement/Services/IIdleShutdown.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace Lombiq.Hosting.Tenants.IdleTenantManagement.Services; | ||
|
||
/// <summary> | ||
/// Service to shut down idle tenants. | ||
/// </summary> | ||
public interface IIdleShutdown | ||
{ | ||
/// <summary> | ||
/// Shuts down idle tenants if they are idle for more than the configured time. | ||
/// </summary> | ||
Task ShutDownIdleTenantsAsync(); | ||
} |
50 changes: 50 additions & 0 deletions
50
Lombiq.Hosting.Tenants.IdleTenantManagement/Services/IdleShutdown.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Lombiq.Hosting.Tenants.IdleTenantManagement.Models; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
using OrchardCore.Environment.Shell; | ||
using OrchardCore.Modules; | ||
using System.Threading.Tasks; | ||
|
||
namespace Lombiq.Hosting.Tenants.IdleTenantManagement.Services; | ||
|
||
public class IdleShutdown : IIdleShutdown | ||
{ | ||
private readonly IOptions<IdleShutdownOptions> _options; | ||
private readonly ShellSettings _shellSettings; | ||
private readonly IClock _clock; | ||
private readonly ILastActiveTimeAccessor _lastActiveTimeAccessor; | ||
private readonly ILogger<IdleShutdown> _logger; | ||
private readonly IShellHost _shellHost; | ||
|
||
public IdleShutdown( | ||
IOptions<IdleShutdownOptions> options, | ||
ShellSettings shellSettings, | ||
IClock clock, | ||
ILastActiveTimeAccessor lastActiveTimeAccessor, | ||
ILogger<IdleShutdown> logger, | ||
IShellHost shellHost) | ||
{ | ||
_options = options; | ||
_shellSettings = shellSettings; | ||
_clock = clock; | ||
_lastActiveTimeAccessor = lastActiveTimeAccessor; | ||
_logger = logger; | ||
_shellHost = shellHost; | ||
} | ||
|
||
public async Task ShutDownIdleTenantsAsync() | ||
{ | ||
var maxIdleMinutes = _options.Value.MaxIdleMinutes; | ||
|
||
if (maxIdleMinutes <= 0 || _shellSettings.IsDefaultShell()) return; | ||
|
||
var lastActiveDateTimeUtc = _lastActiveTimeAccessor.LastActiveDateTimeUtc; | ||
|
||
if (lastActiveDateTimeUtc.AddMinutes(maxIdleMinutes) <= _clock?.UtcNow) | ||
{ | ||
_logger?.LogInformation("Shutting down tenant \"{ShellName}\" because of idle timeout.", _shellSettings.Name); | ||
|
||
await _shellHost.ReleaseShellContextAsync(_shellSettings, eventSource: false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters