コード例 #1
0
 private static void ReportServiceStarted(
     OperationContext context,
     IDistributedCacheServiceHost host)
 {
     LifetimeTracker.ServiceStarted(context);
     host.OnStartedService();
 }
コード例 #2
0
        private static async Task ReportShuttingDownServiceAsync(OperationContext context, IDistributedCacheServiceHost host)
        {
            LifetimeTracker.ShuttingDownService(context);

            if (host is IDistributedCacheServiceHostInternal hostInternal)
            {
                await hostInternal.OnStoppingServiceAsync(context);
            }
        }
コード例 #3
0
        private static LifetimeTracker CreateLifetimeTracker(MemoryClock memoryClock)
        {
            var processStartTimeUtc = memoryClock.UtcNow;

            var startupDuration = TimeSpan.FromSeconds(1);

            memoryClock.UtcNow += TimeSpan.FromSeconds(1);

            Result <DateTime> shutdownTimeUtc = memoryClock.UtcNow - TimeSpan.FromMinutes(5);

            var instance = LifetimeTracker.Started(memoryClock, startupDuration, shutdownTimeUtc, processStartTimeUtc);

            return(instance);
        }
コード例 #4
0
        /// <summary>
        /// Request a graceful shutdown of a current service instance.
        /// </summary>
        /// <remarks> The operation will succeed only if <see cref="SetLifetimeManager"/> method was called.</remarks>
        public static void RequestTeardown(Context context, string reason)
        {
            var lifetimeManager = _lifetimeManager;

            if (lifetimeManager == null)
            {
                context.Warning("Can't teardown the instance because lifetime manager is not available.");
            }
            else
            {
                LifetimeTracker.TeardownRequested(context, reason);
                lifetimeManager.RequestTeardown(reason);
            }
        }
コード例 #5
0
        private static Task ReportStartingServiceAsync(
            OperationContext context,
            IDistributedCacheServiceHost host,
            DistributedCacheServiceArguments arguments)
        {
            var configuration      = arguments.Configuration;
            var logIntervalSeconds = configuration.DistributedContentSettings.ServiceRunningLogInSeconds;
            var logInterval        = logIntervalSeconds != null ? (TimeSpan?)TimeSpan.FromSeconds(logIntervalSeconds.Value) : null;

            var logFilePath = GetPathForLifetimeTracking(configuration);

            LifetimeTracker.ServiceStarting(context, logInterval, logFilePath, arguments.TelemetryFieldsProvider.ServiceName);

            return(host.OnStartingServiceAsync());
        }
コード例 #6
0
        private static async Task ReportServiceStartedAsync(
            OperationContext context,
            StartupShutdownSlimBase server,
            IDistributedCacheServiceHost host)
        {
            LifetimeTracker.ServiceStarted(context);
            host.OnStartedService();

            if (host is IDistributedCacheServiceHostInternal hostInternal &&
                server is IServicesProvider sp &&
                sp.TryGetService <ICacheServerServices>(out var services))
            {
                await hostInternal.OnStartedServiceAsync(context, services);
            }
        }
コード例 #7
0
        public void NormalStartup()
        {
            var logger  = TestGlobal.Logger;
            var context = new Context(logger);

            using var testDirectory = new DisposableDirectory(_fileSystem);
            LifetimeTracker.ServiceStarting(context, serviceRunningLogInterval: TimeSpan.FromMinutes(10), testDirectory.Path);

            LifetimeTracker.ServiceStarted(context);
            GetFullOutput().Should().NotContain(FullyInitializedMessage);

            LifetimeTracker.ServiceReadyToProcessRequests(context);
            var output = GetFullOutput();

            output.Should().Contain(FullyInitializedMessage);
            output.Should().Contain(UnavailableOfflineTime);
        }
コード例 #8
0
        private static async Task ReportStartingServiceAsync(
            OperationContext context,
            IDistributedCacheServiceHost host,
            DistributedCacheServiceConfiguration configuration)
        {
            var logIntervalSeconds = configuration.DistributedContentSettings.ServiceRunningLogInSeconds;
            var logInterval        = logIntervalSeconds != null ? (TimeSpan?)TimeSpan.FromSeconds(logIntervalSeconds.Value) : null;
            var logFilePath        = configuration.LocalCasSettings.GetCacheRootPathWithScenario(LocalCasServiceSettings.DefaultCacheName);

            LifetimeTracker.ServiceStarting(context, logInterval, logFilePath);

            if (host is IDistributedCacheServiceHostInternal hostInternal)
            {
                await hostInternal.OnStartingServiceAsync(context);
            }

            await host.OnStartingServiceAsync();
        }
コード例 #9
0
        private static async Task ReportServiceStartedAsync(
            OperationContext context,
            StartupShutdownSlimBase server,
            IDistributedCacheServiceHost host,
            DistributedContentSettings distributedContentSettings)
        {
            LifetimeTracker.ServiceStarted(context);
            host.OnStartedService();

            if (
                // Don't need to call the following callback for out-of-proc cache
                distributedContentSettings.OutOfProcCacheSettings is null &&
                host is IDistributedCacheServiceHostInternal hostInternal &&
                server is IServicesProvider sp &&
                sp.TryGetService <ICacheServerServices>(out var services))
            {
                await hostInternal.OnStartedServiceAsync(context, services);
            }
        }
コード例 #10
0
        public void TraceWithMultipleStartupAndShutdown()
        {
            var memoryClock = new MemoryClock();
            var logger      = TestGlobal.Logger;
            var context     = new Context(logger);

            var process1StartupTime = memoryClock.UtcNow;

            memoryClock.AddSeconds(10);

            using var testDirectory = new DisposableDirectory(_fileSystem);
            LifetimeTracker.ServiceStarting(context, serviceRunningLogInterval: TimeSpan.FromMinutes(10), testDirectory.Path, memoryClock, process1StartupTime);

            memoryClock.AddSeconds(10);
            LifetimeTracker.ServiceStarted(context, memoryClock);
            memoryClock.AddSeconds(10);
            LifetimeTracker.ServiceReadyToProcessRequests(context);

            // Offline time should be unavailable.
            GetFullOutput().Should().Contain(UnavailableOfflineTime);
            LifetimeTracker.ServiceStopped(context, BoolResult.Success);

            // Now we're running the same stuff the second time, like after the process restart.

            memoryClock.AddSeconds(300);
            var process2StartupTime = memoryClock.UtcNow;

            memoryClock.AddSeconds(10);
            LifetimeTracker.ServiceStarting(context, serviceRunningLogInterval: TimeSpan.FromMinutes(10), testDirectory.Path, memoryClock, process2StartupTime);
            GetFullOutput().Should().Contain("LastHeartBeatTime");

            memoryClock.AddSeconds(10);
            LifetimeTracker.ServiceStarted(context, memoryClock);
            memoryClock.AddSeconds(10);
            LifetimeTracker.ServiceReadyToProcessRequests(context);
            GetFullOutput().Should().Contain("OfflineTime=[00:05:50");
        }
コード例 #11
0
 private static void ReportServiceStopped(Context context, IDistributedCacheServiceHost host, BoolResult result)
 {
     CacheActivityTracker.Stop();
     LifetimeTracker.ServiceStopped(context, result);
     host.OnTeardownCompleted();
 }
コード例 #12
0
 private static void ReportServiceStartupFailed(Context context, Exception exception, TimeSpan startupDuration)
 {
     LifetimeTracker.ServiceStartupFailed(context, exception, startupDuration);
 }