|
| 1 | +// Copyright (c) .NET Foundation. All rights reserved. |
| 2 | +// Licensed under the MIT License. See License.txt in the project root for license information. |
| 3 | + |
| 4 | +using System.Text.Json; |
| 5 | +using System.Text.Json.Serialization; |
| 6 | +using Microsoft.Azure.WebJobs.Hosting; |
| 7 | +using Microsoft.Azure.WebJobs.Script.Configuration; |
| 8 | +using Microsoft.Extensions.Configuration; |
| 9 | + |
| 10 | +namespace Microsoft.Azure.WebJobs.Script |
| 11 | +{ |
| 12 | + /// <summary> |
| 13 | + /// Options that control Script Host recycling behavior. |
| 14 | + /// </summary> |
| 15 | + public sealed class ScriptHostRecycleOptions : IOptionsFormatter |
| 16 | + { |
| 17 | + /// <summary> |
| 18 | + /// Gets or sets a value indicating whether sequential host restarts are required. |
| 19 | + /// </summary> |
| 20 | + public bool SequentialHostRestartRequired { get; set; } |
| 21 | + |
| 22 | + public static ScriptHostRecycleOptions Create(IConfiguration configuration) |
| 23 | + { |
| 24 | + ScriptHostRecycleOptions options = new(); |
| 25 | + options.Configure(configuration); |
| 26 | + return options; |
| 27 | + } |
| 28 | + |
| 29 | + public string Format() |
| 30 | + { |
| 31 | + return JsonSerializer.Serialize(this, typeof(ScriptHostRecycleOptions), ScriptHostRecycleOptionsJsonContext.Default); |
| 32 | + } |
| 33 | + |
| 34 | + internal void Configure(IConfiguration configuration) |
| 35 | + { |
| 36 | + var sequentialRestartSetting = configuration.GetSection(ConfigurationSectionNames.SequentialJobHostRestart); |
| 37 | + if (sequentialRestartSetting != null) |
| 38 | + { |
| 39 | + _ = bool.TryParse(sequentialRestartSetting.Value, out bool enforceSequentialOrder); |
| 40 | + SequentialHostRestartRequired = enforceSequentialOrder; |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + [JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Serialization, WriteIndented = true)] |
| 46 | + [JsonSerializable(typeof(ScriptHostRecycleOptions))] |
| 47 | + internal partial class ScriptHostRecycleOptionsJsonContext : JsonSerializerContext; |
| 48 | +} |
0 commit comments