Skip to content

Commit 93e8040

Browse files
committed
App_Offline.htm file change notification fix
1 parent c835a30 commit 93e8040

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

src/WebJobs.Script.WebHost/FileMonitoringService.cs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,25 @@ private void OnFileChanged(FileSystemEventArgs e)
118118
string changeDescription = string.Empty;
119119
string directory = GetRelativeDirectory(e.FullPath, _scriptOptions.RootScriptPath);
120120
string fileName = Path.GetFileName(e.Name);
121+
bool shutdown = false;
121122

122123
if (_scriptOptions.WatchDirectories.Contains(directory))
123124
{
124125
changeDescription = "Watched directory";
125126
}
126127
else if (string.Compare(fileName, ScriptConstants.AppOfflineFileName, StringComparison.OrdinalIgnoreCase) == 0)
127128
{
128-
OnOfflineFileChanged(e);
129+
// app_offline.htm has changed
130+
// when app_offline.htm is created, we trigger
131+
// a shutdown so when the host starts back up it
132+
// will be offline
133+
// when app_offline.htm is deleted, we trigger
134+
// a restart to bring the host back online
135+
changeDescription = "File";
136+
if (File.Exists(e.FullPath))
137+
{
138+
shutdown = true;
139+
}
129140
}
130141
else if (string.Compare(fileName, ScriptConstants.HostMetadataFileName, StringComparison.OrdinalIgnoreCase) == 0 ||
131142
string.Compare(fileName, ScriptConstants.FunctionMetadataFileName, StringComparison.OrdinalIgnoreCase) == 0 ||
@@ -142,7 +153,6 @@ private void OnFileChanged(FileSystemEventArgs e)
142153

143154
if (!string.IsNullOrEmpty(changeDescription))
144155
{
145-
bool shutdown = false;
146156
string fileExtension = Path.GetExtension(fileName);
147157
if (!string.IsNullOrEmpty(fileExtension) && ScriptConstants.AssemblyFileTypes.Contains(fileExtension, StringComparer.OrdinalIgnoreCase))
148158
{
@@ -239,23 +249,6 @@ public void Dispose()
239249
Dispose(true);
240250
}
241251

242-
private void OnOfflineFileChanged(FileSystemEventArgs e)
243-
{
244-
if (e.ChangeType == WatcherChangeTypes.Created)
245-
{
246-
// when app_offline.htm is created, trigger
247-
// a shutdown so when the host starts back up it
248-
// will be offline
249-
Shutdown();
250-
}
251-
else if (e.ChangeType == WatcherChangeTypes.Deleted)
252-
{
253-
// after deleting app_offline.htm trigger a reinitialization
254-
// to bring the host back online
255-
_scriptEnvironment.RestartHost();
256-
}
257-
}
258-
259252
internal static async Task SetAppOfflineState(string rootPath, bool offline)
260253
{
261254
string path = Path.Combine(rootPath, ScriptConstants.AppOfflineFileName);

0 commit comments

Comments
 (0)