コード例 #1
0
        public ActionResult Restart()
        {
            var ignore = _hostManager.RestartHostAsync(CancellationToken.None)
                         .ContinueWith(t => { }, continuationOptions: TaskContinuationOptions.OnlyOnFaulted);

            return(Accepted());
        }
コード例 #2
0
 public void RestartHost()
 {
     if (_shutdownRequested == 0 && Interlocked.Exchange(ref _restartRequested, 1) == 0)
     {
         _hostManager.RestartHostAsync(CancellationToken.None);
     }
 }
コード例 #3
0
        public async Task SpecializeHostCoreAsync()
        {
            // Go async immediately to ensure that any async context from
            // the PlaceholderSpecializationMiddleware is properly suppressed.
            await Task.Yield();

            _logger.LogInformation(Resources.HostSpecializationTrace);

            // After specialization, we need to ensure that custom timezone
            // settings configured by the user (WEBSITE_TIME_ZONE) are honored.
            // DateTime caches timezone information, so we need to clear the cache.
            TimeZoneInfo.ClearCachedData();

            // Trigger a configuration reload to pick up all current settings
            _configuration?.Reload();

            _hostNameProvider.Reset();

            await _languageWorkerChannelManager.SpecializeAsync();

            NotifyChange();
            await _scriptHostManager.RestartHostAsync();

            await _scriptHostManager.DelayUntilHostReady();
        }
コード例 #4
0
        public async Task <IActionResult> Resume([FromServices] IScriptHostManager scriptHostManager)
        {
            try
            {
                await _resumeSemaphore.WaitAsync();

                ScriptHostState currentState = scriptHostManager.State;

                _logger.LogDebug($"Received request to resume a draining host - host status: {currentState.ToString()}");

                if (currentState != ScriptHostState.Running ||
                    !Utility.TryGetHostService(scriptHostManager, out IDrainModeManager drainModeManager))
                {
                    _logger.LogDebug("The host is not in a state where we can resume.");
                    return(StatusCode(StatusCodes.Status409Conflict));
                }

                _logger.LogDebug($"Drain mode enabled: {drainModeManager.IsDrainModeEnabled}");

                if (drainModeManager.IsDrainModeEnabled)
                {
                    _logger.LogDebug("Starting a new host");
                    await scriptHostManager.RestartHostAsync();
                }

                var status = new ResumeStatus {
                    State = scriptHostManager.State
                };
                return(Ok(status));
            }
            finally
            {
                _resumeSemaphore.Release();
            }
        }
コード例 #5
0
        public async Task SpecializeHostCoreAsync()
        {
            NotifyChange();

            await _scriptHostManager.RestartHostAsync();

            await _scriptHostManager.DelayUntilHostReady();
        }
コード例 #6
0
        private Task RestartAsync()
        {
            if (!_shutdownScheduled && Interlocked.Exchange(ref _restartRequested, 1) == 0)
            {
                return(_scriptHostManager.RestartHostAsync());
            }

            return(Task.CompletedTask);
        }
コード例 #7
0
        public async Task <IActionResult> Disable([FromServices] IScriptHostManager hostManager)
        {
            _logger.LogDebug("Disabling container");
            // Mark the container disabled. We check for this on host restart
            await Utility.MarkContainerDisabled(_logger);

            var tIgnore = Task.Run(() => hostManager.RestartHostAsync());

            return(Ok());
        }
コード例 #8
0
        public async Task WarmUp(HttpRequest request)
        {
            if (request.Query.TryGetValue("restart", out StringValues value) && string.Compare("1", value) == 0)
            {
                await _hostManager.RestartHostAsync(CancellationToken.None);

                // This call is here for sanity, but we should be fully initialized.
                await _hostManager.DelayUntilHostReady();
            }
        }
コード例 #9
0
        public async Task Invoke(HttpContext httpContext, IScriptHostManager manager, ILogger <TestMiddleware> logger)
        {
            if (httpContext.Request.Query.ContainsKey("reset"))
            {
                await manager.RestartHostAsync(CancellationToken.None);

                logger.LogWarning("Environment reset");
                var features        = httpContext.Features;
                var servicesFeature = features.Get <IServiceProvidersFeature>();

                features.Set <IServiceProvidersFeature>(new RequestServicesFeature(httpContext, _scopeFactory));
            }

            await _next(httpContext);
        }
コード例 #10
0
        public async Task SpecializeHostCoreAsync()
        {
            _logger.LogInformation(Resources.HostSpecializationTrace);

            // After specialization, we need to ensure that custom timezone
            // settings configured by the user (WEBSITE_TIME_ZONE) are honored.
            // DateTime caches timezone information, so we need to clear the cache.
            TimeZoneInfo.ClearCachedData();

            // Trigger a configuration reload to pick up all current settings
            _configuration?.Reload();

            NotifyChange();

            await _scriptHostManager.RestartHostAsync();

            await _scriptHostManager.DelayUntilHostReady();
        }
コード例 #11
0
        public async Task SpecializeHostCoreAsync()
        {
            // Go async immediately to ensure that any async context from
            // the PlaceholderSpecializationMiddleware is properly suppressed.
            await Task.Yield();

            _logger.LogInformation(Resources.HostSpecializationTrace);

            // After specialization, we need to ensure that custom timezone
            // settings configured by the user (WEBSITE_TIME_ZONE) are honored.
            // DateTime caches timezone information, so we need to clear the cache.
            TimeZoneInfo.ClearCachedData();

            // Trigger a configuration reload to pick up all current settings
            _configuration?.Reload();

            _hostNameProvider.Reset();

            // Reset the shared load context to ensure we're reloading
            // user dependencies
            FunctionAssemblyLoadContext.ResetSharedContext();

            // Signals change of JobHost options from placeholder mode
            // (ex: ScriptPath is updated)
            NotifyChange();

            using (_metricsLogger.LatencyEvent(MetricEventNames.SpecializationLanguageWorkerChannelManagerSpecialize))
            {
                await _rpcWorkerChannelManager.SpecializeAsync();
            }

            using (_metricsLogger.LatencyEvent(MetricEventNames.SpecializationRestartHost))
            {
                await _scriptHostManager.RestartHostAsync();
            }

            using (_metricsLogger.LatencyEvent(MetricEventNames.SpecializationDelayUntilHostReady))
            {
                await _scriptHostManager.DelayUntilHostReady();
            }
        }
コード例 #12
0
 // TODO: DI (FACAVAL) Remove this method.
 // all restart/shutdown requests should go through the
 internal Task RestartAsync()
 {
     _scriptHostManager.RestartHostAsync();
     return(Task.CompletedTask);
 }
コード例 #13
0
        public IActionResult Restart([FromServices] IScriptHostManager hostManager)
        {
            Task ignore = hostManager.RestartHostAsync();

            return(Ok(_applicationHostOptions.Value));
        }