@@ -191,10 +191,13 @@ public override async Task<ExecutionStatus> ExecuteTask(CancellationToken cancel
191191 try
192192 {
193193 var monitor = _scope . ServiceProvider . GetService < IContainerStatusMonitor > ( ) ?? throw new ServiceNotFoundException ( nameof ( IContainerStatusMonitor ) ) ;
194- _ = Task . Run ( async ( ) =>
194+ var monitorTask = Task . Run ( async ( ) =>
195195 {
196- await monitor . Start ( Event , _containerTimeout , containerId , intermediateVolumeMount , outputVolumeMounts , cancellationToken ) ;
196+ await monitor . Start ( Event , _containerTimeout , containerId , intermediateVolumeMount , outputVolumeMounts , CancellationToken . None ) ;
197197 } ) ;
198+ _ = monitorTask . ContinueWith (
199+ t => _logger . ErrorLaunchingContainerMonitor ( containerId , t . Exception ! . GetBaseException ( ) ) ,
200+ TaskContinuationOptions . OnlyOnFaulted ) ;
198201 }
199202 catch ( Exception exception )
200203 {
@@ -244,10 +247,32 @@ public override async Task<ExecutionStatus> GetStatus(string identity, TaskCallb
244247 var stats = GetExecutuionStats ( response ) ;
245248 if ( ContainerStatusMonitor . IsContainerCompleted ( response . State ) )
246249 {
250+ if ( response . State . OOMKilled || response . State . Dead )
251+ {
252+ return new ExecutionStatus
253+ {
254+ Status = TaskExecutionStatus . Failed ,
255+ FailureReason = FailureReason . ExternalServiceError ,
256+ Errors = $ "Exit code={ response . State . ExitCode } ",
257+ Stats = stats
258+ } ;
259+ }
260+
261+ if ( response . State . ExitCode == 0 )
262+ {
263+ return new ExecutionStatus
264+ {
265+ Status = TaskExecutionStatus . Succeeded ,
266+ FailureReason = FailureReason . None ,
267+ Stats = stats
268+ } ;
269+ }
270+
247271 return new ExecutionStatus
248272 {
249- Status = TaskExecutionStatus . Succeeded ,
250- FailureReason = FailureReason . None ,
273+ Status = TaskExecutionStatus . Failed ,
274+ FailureReason = FailureReason . Unknown ,
275+ Errors = $ "Exit code={ response . State . ExitCode } . Status={ response . State . Status } .",
251276 Stats = stats
252277 } ;
253278 }
@@ -334,7 +359,7 @@ private PodmanCreateContainerRequest BuildContainerSpecification(IList<Container
334359 Source = input . HostPath ,
335360 Options = new List < string > { "rbind" , "ro" }
336361 } ) ;
337- _logger . DockerInputMapped ( input . HostPath , input . ContainerPath ) ;
362+ _logger . PodmanInputMapped ( input . HostPath , input . ContainerPath ) ;
338363 }
339364
340365 foreach ( var output in outputs )
@@ -346,7 +371,7 @@ private PodmanCreateContainerRequest BuildContainerSpecification(IList<Container
346371 Source = output . HostPath ,
347372 Options = new List < string > { "rbind" , "rw" }
348373 } ) ;
349- _logger . DockerOutputMapped ( output . HostPath , output . ContainerPath ) ;
374+ _logger . PodmanOutputMapped ( output . HostPath , output . ContainerPath ) ;
350375 }
351376
352377 if ( intermediateVolumeMount is not null )
@@ -358,7 +383,7 @@ private PodmanCreateContainerRequest BuildContainerSpecification(IList<Container
358383 Source = intermediateVolumeMount . HostPath ,
359384 Options = new List < string > { "rbind" , "rw" }
360385 } ) ;
361- _logger . DockerIntermediateVolumeMapped ( intermediateVolumeMount . HostPath , intermediateVolumeMount . ContainerPath ) ;
386+ _logger . PodmanIntermediateVolumeMapped ( intermediateVolumeMount . HostPath , intermediateVolumeMount . ContainerPath ) ;
362387 }
363388
364389 var envvars = new Dictionary < string , string > ( ) ;
@@ -369,7 +394,7 @@ private PodmanCreateContainerRequest BuildContainerSpecification(IList<Container
369394 {
370395 var envVarKey = key . Replace ( Keys . EnvironmentVariableKeyPrefix , string . Empty ) ;
371396 envvars [ envVarKey ] = Event . TaskPluginArguments [ key ] ;
372- _logger . DockerEnvironmentVariableAdded ( envVarKey , Event . TaskPluginArguments [ key ] ) ;
397+ _logger . PodmanEnvironmentVariableAdded ( envVarKey ) ;
373398 }
374399 }
375400
@@ -449,9 +474,10 @@ private async Task<List<ContainerVolumeMount>> SetupInputs(CancellationToken can
449474 Directory . CreateDirectory ( fileDirectory ! ) ;
450475
451476 _logger . DownloadingArtifactFromStorageService ( obj . Filename , filePath ) ;
452- using var stream = await storageService . GetObjectAsync ( input . Bucket , obj . FilePath , cancellationToken ) . ConfigureAwait ( false ) as MemoryStream ;
477+ using var stream = await storageService . GetObjectAsync ( input . Bucket , obj . FilePath , cancellationToken ) . ConfigureAwait ( false )
478+ ?? throw new InvalidOperationException ( $ "Unable to download '{ obj . FilePath } ' from bucket '{ input . Bucket } '.") ;
453479 using var fileStream = new FileStream ( filePath , FileMode . CreateNew , FileAccess . Write ) ;
454- stream ! . WriteTo ( fileStream ) ;
480+ await stream . CopyToAsync ( fileStream , cancellationToken ) . ConfigureAwait ( false ) ;
455481 }
456482 }
457483
@@ -520,8 +546,9 @@ private void SetPermission(string path)
520546
521547 if ( process . ExitCode != 0 )
522548 {
523- _logger . ErrorSettingDirectoryPermission ( path , Event . TaskPluginArguments [ Keys . User ] ) ;
524- throw new SetPermissionException ( $ "chown command exited with code { process . ExitCode } ") ;
549+ var permissionException = new SetPermissionException ( $ "chown command exited with code { process . ExitCode } ") ;
550+ _logger . ErrorSettingDirectoryPermission ( permissionException , path , Event . TaskPluginArguments [ Keys . User ] ) ;
551+ throw permissionException ;
525552 }
526553 }
527554 }
0 commit comments