Skip to content

Commit 940e1a0

Browse files
authored
Updating HostWarmupMiddleware to work with placeholder simulation locally. (#9660)
* Updating WarmupMiddleware to work with placeholder simulation locally. * Update release notes * run warmup code for HP call when in placeholdersimulation mode. * Updates to trigger warmup code when home page is requested in placeholder simulation mode.
1 parent a4ed442 commit 940e1a0

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

release_notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
- Upgrading dependent packages to latest versions. #9646
2727
- Azure.Identity (1.10.0 to 1.10.3)
2828
- Azure.Core (1.34.0 to 1.35.0)
29+
- Updating HostWarmupMiddleware to trigger warmup code on home page request when testing locally using DebugPlaceholder or ReleasePlaceholder configuration.
2930
- Bug fix: Comparisons in the Azure Key Vault Secrets Repository are now case insensitive (#9644)
3031
- This fixes a bug where keys could be automatically recreated if they had been manually added to Key Vault with all lowercase secret names
3132
- Update DotNetIsolatedNativeHost version to 1.0.3 (#9671)

src/WebJobs.Script.WebHost/Middleware/HostWarmupMiddleware.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public HostWarmupMiddleware(
5353

5454
public Task Invoke(HttpContext httpContext)
5555
{
56-
if (IsWarmUpRequest(httpContext.Request, _webHostEnvironment.InStandbyMode, _environment))
56+
if (_webHostEnvironment.InStandbyMode)
5757
{
5858
return WarmupInvoke(httpContext);
5959
}
@@ -167,6 +167,13 @@ public async Task HostWarmupAsync(HttpRequest request)
167167

168168
public static bool IsWarmUpRequest(HttpRequest request, bool inStandbyMode, IEnvironment environment)
169169
{
170+
// In placeholder simulation mode, we want the homepage request to also trigger warmup code.
171+
var isWarmupViaHomePageRequest = Utility.IsInPlaceholderSimulationMode && inStandbyMode && request.Path.Value == "/";
172+
if (isWarmupViaHomePageRequest)
173+
{
174+
return true;
175+
}
176+
170177
return inStandbyMode
171178
&& ((environment.IsAppService() && request.IsAppServiceInternalRequest(environment)) || environment.IsAnyLinuxConsumption())
172179
&& (request.Path.StartsWithSegments(_warmupRoutePath) || request.Path.StartsWithSegments(_warmupRouteAlternatePath));

src/WebJobs.Script/Utility.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ public static class Utility
4444
private const string SasVersionQueryParam = "sv";
4545
private const string SasTokenExpirationDate = "se";
4646

47+
/// <summary>
48+
/// Gets a value indicating whether the host is running in placeholder simulation mode.
49+
/// This mode is used for testing placeholder scenarios locally.
50+
/// Running using either "DebugPlaceholder" or "ReleasePlaceholder" configuration mode will
51+
/// cause the host to run in placeholder simulation mode.
52+
/// </summary>
53+
#if PLACEHOLDERSIMULATION
54+
public const bool IsInPlaceholderSimulationMode = true;
55+
#else
56+
public const bool IsInPlaceholderSimulationMode = false;
57+
#endif
58+
4759
private static readonly Regex FunctionNameValidationRegex = new Regex(@"^[a-z][a-z0-9_\-]{0,127}$(?<!^host$)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
4860
private static readonly Regex BindingNameValidationRegex = new Regex(string.Format("^([a-zA-Z][a-zA-Z0-9]{{0,127}}|{0})$", Regex.Escape(ScriptConstants.SystemReturnParameterBindingName)));
4961

@@ -52,12 +64,6 @@ public static class Utility
5264

5365
private static List<string> dotNetLanguages = new List<string>() { DotNetScriptTypes.CSharp, DotNetScriptTypes.DotNetAssembly };
5466

55-
#if PLACEHOLDERSIMULATION
56-
private static bool isInPlaceholderSimulationMode = true;
57-
#else
58-
private static bool isInPlaceholderSimulationMode = false;
59-
#endif
60-
6167
public static int ColdStartDelayMS { get; set; } = 5000;
6268

6369
internal static bool TryGetHostService<TService>(IScriptHostManager scriptHostManager, out TService service) where TService : class
@@ -780,7 +786,7 @@ public static void ExecuteAfterDelay(Action targetAction, TimeSpan delay, Cancel
780786
public static void ExecuteAfterColdStartDelay(IEnvironment environment, Action targetAction, CancellationToken cancellationToken = default)
781787
{
782788
// for Dynamic SKUs where coldstart is important, we want to delay the action
783-
if (isInPlaceholderSimulationMode || environment.IsDynamicSku())
789+
if (IsInPlaceholderSimulationMode || environment.IsDynamicSku())
784790
{
785791
ExecuteAfterDelay(targetAction, TimeSpan.FromMilliseconds(ColdStartDelayMS), cancellationToken);
786792
}

0 commit comments

Comments
 (0)