public async Task SetState()

in src/WebJobs.Script.WebHost/Controllers/HostController.cs [479:519]


        public async Task<IActionResult> SetState([FromBody] string state)
        {
            if (!Enum.TryParse<ScriptHostState>(state, ignoreCase: true, out ScriptHostState desiredState) ||
                !(desiredState == ScriptHostState.Offline || desiredState == ScriptHostState.Running))
            {
                // currently we only allow states Offline and Running
                return BadRequest();
            }

            var currentState = _scriptHostManager.State;
            if (desiredState == currentState)
            {
                return Ok();
            }
            else if (desiredState == ScriptHostState.Running && currentState == ScriptHostState.Offline)
            {
                if (_applicationHostOptions.Value.IsFileSystemReadOnly)
                {
                    return BadRequest();
                }

                // we're currently offline and the request is to bring the host back online
                await FileMonitoringService.SetAppOfflineState(_applicationHostOptions.Value.ScriptPath, false);
            }
            else if (desiredState == ScriptHostState.Offline && currentState != ScriptHostState.Offline)
            {
                if (_applicationHostOptions.Value.IsFileSystemReadOnly)
                {
                    return BadRequest();
                }

                // we're currently online and the request is to take the host offline
                await FileMonitoringService.SetAppOfflineState(_applicationHostOptions.Value.ScriptPath, true);
            }
            else
            {
                return BadRequest();
            }

            return Accepted();
        }