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();
            }
        }
        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());
        }
        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();
            }
        }
        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);
        }
        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();
        }
        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);
 }
        public IActionResult Restart([FromServices] IScriptHostManager hostManager)
        {
            Task ignore = hostManager.RestartHostAsync();

            return(Ok(_applicationHostOptions.Value));
        }