Skip to content

Commit 6fc6559

Browse files
committed
Skip file watching in ReadOnly mode
1 parent 0766b39 commit 6fc6559

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/WebJobs.Script/Host/ScriptHost.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,12 @@ public void Initialize()
371371

372372
ApplyConfiguration(hostConfigObject, ScriptConfig);
373373

374+
if (_settingsManager.FileSystemIsReadOnly)
375+
{
376+
// we're in read-only mode so source files can't change
377+
ScriptConfig.FileWatchingEnabled = false;
378+
}
379+
374380
// now the configuration has been read and applied re-create the logger
375381
// factory and loggers ensuring that filters and settings have been applied
376382
ConfigureLoggerFactory(recreate: true);
@@ -415,6 +421,9 @@ public void Initialize()
415421
_fileEventsSubscription = EventManager.OfType<FileEvent>()
416422
.Where(f => string.Equals(f.Source, EventSources.ScriptFiles, StringComparison.Ordinal))
417423
.Subscribe(e => OnFileChanged(e.FileChangeArguments));
424+
425+
// take a snapshot so we can detect function additions/removals
426+
_directorySnapshot = Directory.EnumerateDirectories(ScriptConfig.RootScriptPath).ToImmutableArray();
418427
}
419428

420429
// If a file change should result in a restart, we debounce the event to
@@ -428,9 +437,6 @@ public void Initialize()
428437
_shutdown = Shutdown;
429438
_shutdown = _shutdown.Debounce(500);
430439

431-
// take a snapshot so we can detect function additions/removals
432-
_directorySnapshot = Directory.EnumerateDirectories(ScriptConfig.RootScriptPath).ToImmutableArray();
433-
434440
// Scan the function.json early to determine the binding extensions used
435441
var functionMetadata = ReadFunctionMetadata(ScriptConfig, TraceWriter, _startupLogger, FunctionErrors, _settingsManager);
436442
var extensionLoader = new ExtensionLoader(ScriptConfig, TraceWriter, _startupLogger);

src/WebJobs.Script/Host/ScriptHostManager.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,6 @@ public class ScriptHostManager : IScriptHostEnvironment, IDisposable
5555
public ScriptHostManager(ScriptHostConfiguration config, IScriptEventManager eventManager = null, IScriptHostEnvironment environment = null, HostPerformanceManager hostPerformanceManager = null)
5656
: this(config, ScriptSettingsManager.Instance, new ScriptHostFactory(), eventManager, environment, hostPerformanceManager)
5757
{
58-
if (config.FileWatchingEnabled)
59-
{
60-
// We only setup a subscription here as the actual ScriptHost will create the publisher
61-
// when initialized.
62-
_fileEventSubscription = EventManager.OfType<FileEvent>()
63-
.Where(f => string.Equals(f.Source, EventSources.ScriptFiles, StringComparison.Ordinal))
64-
.Subscribe(e => OnScriptFileChanged(null, e.FileChangeArguments));
65-
}
6658
}
6759

6860
public ScriptHostManager(ScriptHostConfiguration config,
@@ -92,6 +84,15 @@ public ScriptHostManager(ScriptHostConfiguration config,
9284
_structuredLogWriter = new StructuredLogWriter(EventManager, config.RootLogPath);
9385
_performanceManager = hostPerformanceManager ?? new HostPerformanceManager(settingsManager, _config.HostHealthMonitor);
9486

87+
if (config.FileWatchingEnabled && !settingsManager.FileSystemIsReadOnly)
88+
{
89+
// We only setup a subscription here as the actual ScriptHost will create the publisher
90+
// when initialized.
91+
_fileEventSubscription = EventManager.OfType<FileEvent>()
92+
.Where(f => string.Equals(f.Source, EventSources.ScriptFiles, StringComparison.Ordinal))
93+
.Subscribe(e => OnScriptFileChanged(null, e.FileChangeArguments));
94+
}
95+
9596
if (ShouldMonitorHostHealth)
9697
{
9798
_hostHealthCheckTimer = new Timer(OnHostHealthCheckTimer, null, TimeSpan.Zero, _config.HostHealthMonitor.HealthCheckInterval);

0 commit comments

Comments
 (0)