@@ -39,6 +39,7 @@ namespace Microsoft.Azure.WebJobs.Script
39
39
public class ScriptHost : JobHost , IScriptJobHost
40
40
{
41
41
internal const int DebugModeTimeoutMinutes = 15 ;
42
+ private const int FileSystemCleanupDelay = 30 ;
42
43
private const string HostAssemblyName = "ScriptHost" ;
43
44
private const string GeneratedTypeNamespace = "Host" ;
44
45
internal const string GeneratedTypeName = "Functions" ;
@@ -47,6 +48,7 @@ public class ScriptHost : JobHost, IScriptJobHost
47
48
private readonly string _storageConnectionString ;
48
49
private readonly IDistributedLockManager _distributedLockManager ;
49
50
private readonly IFunctionMetadataManager _functionMetadataManager ;
51
+ private readonly IFileLoggingStatusManager _fileLoggingStatusManager ;
50
52
private readonly IHostIdProvider _hostIdProvider ;
51
53
private readonly IHttpRoutesManager _httpRoutesManager ;
52
54
private readonly IProxyMetadataManager _proxyMetadataManager ;
@@ -91,6 +93,7 @@ public ScriptHost(IOptions<JobHostOptions> options,
91
93
ILoggerFactory loggerFactory ,
92
94
IFunctionInvocationDispatcherFactory functionDispatcherFactory ,
93
95
IFunctionMetadataManager functionMetadataManager ,
96
+ IFileLoggingStatusManager fileLoggingStatusManager ,
94
97
IProxyMetadataManager proxyMetadataManager ,
95
98
IMetricsLogger metricsLogger ,
96
99
IOptions < ScriptJobHostOptions > scriptHostOptions ,
@@ -116,6 +119,7 @@ public ScriptHost(IOptions<JobHostOptions> options,
116
119
_storageConnectionString = configuration . GetWebJobsConnectionString ( ConnectionStringNames . Storage ) ;
117
120
_distributedLockManager = distributedLockManager ;
118
121
_functionMetadataManager = functionMetadataManager ;
122
+ _fileLoggingStatusManager = fileLoggingStatusManager ;
119
123
_applicationLifetime = applicationLifetime ;
120
124
_hostIdProvider = hostIdProvider ;
121
125
_httpRoutesManager = httpRoutesManager ;
@@ -296,7 +300,7 @@ public async Task InitializeAsync(CancellationToken cancellationToken = default)
296
300
297
301
GenerateFunctions ( directTypes ) ;
298
302
299
- CleanupFileSystem ( ) ;
303
+ ScheduleFileSystemCleanup ( ) ;
300
304
}
301
305
}
302
306
@@ -445,7 +449,10 @@ private void PreInitialize()
445
449
/// </summary>
446
450
private void InitializeFileSystem ( )
447
451
{
448
- FileUtility . EnsureDirectoryExists ( _hostLogPath ) ;
452
+ if ( _fileLoggingStatusManager . IsFileLoggingEnabled )
453
+ {
454
+ FileUtility . EnsureDirectoryExists ( _hostLogPath ) ;
455
+ }
449
456
450
457
if ( ! _environment . IsFileSystemReadOnly ( ) )
451
458
{
@@ -521,14 +528,15 @@ private void AddFunctionDescriptors()
521
528
/// <summary>
522
529
/// Clean up any old files or directories.
523
530
/// </summary>
524
- private void CleanupFileSystem ( )
531
+ private void ScheduleFileSystemCleanup ( )
525
532
{
526
- if ( ScriptOptions . FileLoggingMode != FileLoggingMode . Never )
533
+ Utility . ExecuteAfterDelay ( ( ) =>
527
534
{
528
- // initiate the cleanup in a background task so we don't
529
- // delay startup
530
- Task . Run ( ( ) => PurgeOldLogDirectories ( ) ) ;
531
- }
535
+ if ( ScriptOptions . FileLoggingMode != FileLoggingMode . Never )
536
+ {
537
+ PurgeOldLogDirectories ( ) ;
538
+ }
539
+ } , TimeSpan . FromSeconds ( FileSystemCleanupDelay ) ) ;
532
540
}
533
541
534
542
/// <summary>
0 commit comments