Skip to content

Commit 1633385

Browse files
authored
Fix cold start regression (#8505)
1 parent 1bf8720 commit 1633385

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/WebJobs.Script/Host/DebugStateProvider.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ internal class DebugStateProvider : IDebugStateProvider, IDisposable
1414
internal const int DebugModeTimeoutMinutes = 15;
1515
internal const int DiagnosticModeTimeoutHours = 3;
1616
private readonly IOptionsMonitor<ScriptApplicationHostOptions> _scriptOptions;
17+
private readonly IEnvironment _environment;
1718
private IDisposable _debugModeEvent;
1819
private IDisposable _diagnosticModeEvent;
1920
private bool _disposed;
2021

21-
public DebugStateProvider(IOptionsMonitor<ScriptApplicationHostOptions> scriptOptions, IScriptEventManager eventManager)
22+
public DebugStateProvider(IEnvironment environment, IOptionsMonitor<ScriptApplicationHostOptions> scriptOptions, IScriptEventManager eventManager)
2223
{
24+
_environment = environment;
2325
_debugModeEvent = eventManager.OfType<DebugNotification>()
2426
.Subscribe(evt => LastDebugNotify = evt.NotificationTime);
2527
_diagnosticModeEvent = eventManager.OfType<DiagnosticNotification>()
@@ -41,8 +43,11 @@ public DebugStateProvider(IOptionsMonitor<ScriptApplicationHostOptions> scriptOp
4143

4244
private void InitializeLastNotificationTimes()
4345
{
44-
LastDebugNotify = GetLastWriteTime(ScriptConstants.DebugSentinelFileName);
45-
LastDiagnosticNotify = GetLastWriteTime(ScriptConstants.DiagnosticSentinelFileName);
46+
Utility.ExecuteAfterColdStartDelay(_environment, () =>
47+
{
48+
LastDebugNotify = GetLastWriteTime(ScriptConstants.DebugSentinelFileName);
49+
LastDiagnosticNotify = GetLastWriteTime(ScriptConstants.DiagnosticSentinelFileName);
50+
});
4651
}
4752

4853
private DateTime GetLastWriteTime(string fileName)

test/WebJobs.Script.Tests/Diagnostics/DebugStateProviderTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public class DebugStateProviderTests
1717

1818
public DebugStateProviderTests()
1919
{
20+
var environment = new TestEnvironment();
21+
2022
_options = new ScriptApplicationHostOptions
2123
{
2224
LogPath = Path.Combine(Directory.GetCurrentDirectory(), "DebugPath1")
@@ -27,7 +29,7 @@ public DebugStateProviderTests()
2729
var changeTokens = new[] { _tokenSource };
2830
var optionsMonitor = new OptionsMonitor<ScriptApplicationHostOptions>(factory, changeTokens, factory);
2931

30-
_provider = new DebugStateProvider(optionsMonitor, new ScriptEventManager());
32+
_provider = new DebugStateProvider(environment, optionsMonitor, new ScriptEventManager());
3133
}
3234

3335
[Fact]

0 commit comments

Comments
 (0)