@@ -20,7 +20,7 @@ public interface IJobServerQueue : IRunnerService, IThrottlingReporter
2020 void Start ( Pipelines . AgentJobRequestMessage jobRequest ) ;
2121 void QueueWebConsoleLine ( Guid stepRecordId , string line , long ? lineNumber = null ) ;
2222 void QueueFileUpload ( Guid timelineId , Guid timelineRecordId , string type , string name , string path , bool deleteSource ) ;
23- void QueueResultsUpload ( Guid timelineRecordId , string name , string path , string type , bool deleteSource , bool finalize , bool firstBlock , long totalLines = 0 ) ;
23+ void QueueSummaryUpload ( Guid stepRecordId , string name , string path , bool deleteSource ) ;
2424 void QueueTimelineRecordUpdate ( Guid timelineId , TimelineRecord timelineRecord ) ;
2525 }
2626
@@ -31,7 +31,7 @@ public sealed class JobServerQueue : RunnerService, IJobServerQueue
3131 private static readonly TimeSpan _delayForWebConsoleLineDequeue = TimeSpan . FromMilliseconds ( 500 ) ;
3232 private static readonly TimeSpan _delayForTimelineUpdateDequeue = TimeSpan . FromMilliseconds ( 500 ) ;
3333 private static readonly TimeSpan _delayForFileUploadDequeue = TimeSpan . FromMilliseconds ( 1000 ) ;
34- private static readonly TimeSpan _delayForResultsUploadDequeue = TimeSpan . FromMilliseconds ( 1000 ) ;
34+ private static readonly TimeSpan _delayForSummaryUploadDequeue = TimeSpan . FromMilliseconds ( 1000 ) ;
3535
3636 // Job message information
3737 private Guid _scopeIdentifier ;
@@ -46,7 +46,7 @@ public sealed class JobServerQueue : RunnerService, IJobServerQueue
4646 // queue for file upload (log file or attachment)
4747 private readonly ConcurrentQueue < UploadFileInfo > _fileUploadQueue = new ( ) ;
4848
49- private readonly ConcurrentQueue < ResultsUploadFileInfo > _resultsFileUploadQueue = new ( ) ;
49+ private readonly ConcurrentQueue < SummaryUploadFileInfo > _summaryFileUploadQueue = new ( ) ;
5050
5151 // queue for timeline or timeline record update (one queue per timeline)
5252 private readonly ConcurrentDictionary < Guid , ConcurrentQueue < TimelineRecord > > _timelineUpdateQueue = new ( ) ;
@@ -60,7 +60,7 @@ public sealed class JobServerQueue : RunnerService, IJobServerQueue
6060 // Task for each queue's dequeue process
6161 private Task _webConsoleLineDequeueTask ;
6262 private Task _fileUploadDequeueTask ;
63- private Task _resultsUploadDequeueTask ;
63+ private Task _summaryUploadDequeueTask ;
6464 private Task _timelineUpdateDequeueTask ;
6565
6666 // common
@@ -140,12 +140,12 @@ public void Start(Pipelines.AgentJobRequestMessage jobRequest)
140140 _fileUploadDequeueTask = ProcessFilesUploadQueueAsync ( ) ;
141141
142142 Trace . Info ( "Start results file upload queue." ) ;
143- _resultsUploadDequeueTask = ProcessResultsUploadQueueAsync ( ) ;
143+ _summaryUploadDequeueTask = ProcessSummaryUploadQueueAsync ( ) ;
144144
145145 Trace . Info ( "Start process timeline update queue." ) ;
146146 _timelineUpdateDequeueTask = ProcessTimelinesUpdateQueueAsync ( ) ;
147147
148- _allDequeueTasks = new Task [ ] { _webConsoleLineDequeueTask , _fileUploadDequeueTask , _timelineUpdateDequeueTask , _resultsUploadDequeueTask } ;
148+ _allDequeueTasks = new Task [ ] { _webConsoleLineDequeueTask , _fileUploadDequeueTask , _timelineUpdateDequeueTask , _summaryUploadDequeueTask } ;
149149 _queueInProcess = true ;
150150 }
151151
@@ -176,9 +176,9 @@ public async Task ShutdownAsync()
176176 await ProcessFilesUploadQueueAsync ( runOnce : true ) ;
177177 Trace . Info ( "File upload queue drained." ) ;
178178
179- Trace . Verbose ( "Draining results upload queue." ) ;
180- await ProcessResultsUploadQueueAsync ( runOnce : true ) ;
181- Trace . Info ( "Results upload queue drained." ) ;
179+ Trace . Verbose ( "Draining results summary upload queue." ) ;
180+ await ProcessSummaryUploadQueueAsync ( runOnce : true ) ;
181+ Trace . Info ( "Results summary upload queue drained." ) ;
182182
183183 // ProcessTimelinesUpdateQueueAsync() will throw exception during shutdown
184184 // if there is any timeline records that failed to update contains output variabls.
@@ -230,31 +230,21 @@ public void QueueFileUpload(Guid timelineId, Guid timelineRecordId, string type,
230230 _fileUploadQueue . Enqueue ( newFile ) ;
231231 }
232232
233- public void QueueResultsUpload ( Guid recordId , string name , string path , string type , bool deleteSource , bool finalize , bool firstBlock , long totalLines )
233+ public void QueueSummaryUpload ( Guid stepRecordId , string name , string path , bool deleteSource )
234234 {
235- if ( recordId == _jobTimelineRecordId )
236- {
237- Trace . Verbose ( "Skipping job log {0} for record {1}" , path , recordId ) ;
238- return ;
239- }
240-
241235 // all parameter not null, file path exist.
242- var newFile = new ResultsUploadFileInfo ( )
236+ var newFile = new SummaryUploadFileInfo ( )
243237 {
244238 Name = name ,
245239 Path = path ,
246- Type = type ,
247240 PlanId = _planId . ToString ( ) ,
248241 JobId = _jobTimelineRecordId . ToString ( ) ,
249- RecordId = recordId ,
250- DeleteSource = deleteSource ,
251- Finalize = finalize ,
252- FirstBlock = firstBlock ,
253- TotalLines = totalLines ,
242+ StepId = stepRecordId . ToString ( ) ,
243+ DeleteSource = deleteSource
254244 } ;
255245
256- Trace . Verbose ( "Enqueue results file upload queue: file '{0}' attach to job {1} step {2}" , newFile . Path , _jobTimelineRecordId , recordId ) ;
257- _resultsFileUploadQueue . Enqueue ( newFile ) ;
246+ Trace . Verbose ( "Enqueue results file upload queue: file '{0}' attach to job {1} step {2}" , newFile . Path , _jobTimelineRecordId , stepRecordId ) ;
247+ _summaryFileUploadQueue . Enqueue ( newFile ) ;
258248 }
259249
260250 public void QueueTimelineRecordUpdate ( Guid timelineId , TimelineRecord timelineRecord )
@@ -447,18 +437,18 @@ private async Task ProcessFilesUploadQueueAsync(bool runOnce = false)
447437 }
448438 }
449439
450- private async Task ProcessResultsUploadQueueAsync ( bool runOnce = false )
440+ private async Task ProcessSummaryUploadQueueAsync ( bool runOnce = false )
451441 {
452442 Trace . Info ( "Starting results-based upload queue..." ) ;
453443
454444 while ( ! _jobCompletionSource . Task . IsCompleted || runOnce )
455445 {
456- List < ResultsUploadFileInfo > filesToUpload = new ( ) ;
457- ResultsUploadFileInfo dequeueFile ;
458- while ( _resultsFileUploadQueue . TryDequeue ( out dequeueFile ) )
446+ List < SummaryUploadFileInfo > filesToUpload = new ( ) ;
447+ SummaryUploadFileInfo dequeueFile ;
448+ while ( _summaryFileUploadQueue . TryDequeue ( out dequeueFile ) )
459449 {
460450 filesToUpload . Add ( dequeueFile ) ;
461- // process at most 10 file uploads .
451+ // process at most 10 file upload .
462452 if ( ! runOnce && filesToUpload . Count > 10 )
463453 {
464454 break ;
@@ -469,30 +459,19 @@ private async Task ProcessResultsUploadQueueAsync(bool runOnce = false)
469459 {
470460 if ( runOnce )
471461 {
472- Trace . Info ( $ "Uploading { filesToUpload . Count } file(s) in one shot through results service.") ;
462+ Trace . Info ( $ "Uploading { filesToUpload . Count } summary files in one shot through results service.") ;
473463 }
474464
475465 int errorCount = 0 ;
476466 foreach ( var file in filesToUpload )
477467 {
478468 try
479469 {
480- if ( String . Equals ( file . Type , ChecksAttachmentType . StepSummary , StringComparison . OrdinalIgnoreCase ) )
481- {
482- await UploadSummaryFile ( file ) ;
483- }
484- else if ( String . Equals ( file . Type , CoreAttachmentType . ResultsLog , StringComparison . OrdinalIgnoreCase ) )
485- {
486- if ( file . RecordId != _jobTimelineRecordId )
487- {
488- Trace . Info ( $ "Got a step log file to send to results service.") ;
489- await UploadResultsStepLogFile ( file ) ;
490- }
491- }
470+ await UploadSummaryFile ( file ) ;
492471 }
493472 catch ( Exception ex )
494473 {
495- var issue = new Issue ( ) { Type = IssueType . Warning , Message = $ "Caught exception during file upload to results. { ex . Message } " } ;
474+ var issue = new Issue ( ) { Type = IssueType . Warning , Message = $ "Caught exception during summary file upload to results. { ex . Message } " } ;
496475 issue . Data [ Constants . Runner . InternalTelemetryIssueDataKey ] = Constants . Runner . ResultsUploadFailure ;
497476
498477 var telemetryRecord = new TimelineRecord ( )
@@ -502,13 +481,16 @@ private async Task ProcessResultsUploadQueueAsync(bool runOnce = false)
502481 telemetryRecord . Issues . Add ( issue ) ;
503482 QueueTimelineRecordUpdate ( _jobTimelineId , telemetryRecord ) ;
504483
505- Trace . Info ( "Catch exception during file upload to results, keep going since the process is best effort." ) ;
484+ Trace . Info ( "Catch exception during summary file upload to results, keep going since the process is best effort." ) ;
506485 Trace . Error ( ex ) ;
486+ }
487+ finally
488+ {
507489 errorCount ++ ;
508490 }
509491 }
510492
511- Trace . Info ( "Tried to upload {0} file(s) to results, success rate: {1}/{0}." , filesToUpload . Count , filesToUpload . Count - errorCount ) ;
493+ Trace . Info ( "Tried to upload {0} summary files to results, success rate: {1}/{0}." , filesToUpload . Count , filesToUpload . Count - errorCount ) ;
512494 }
513495
514496 if ( runOnce )
@@ -517,7 +499,7 @@ private async Task ProcessResultsUploadQueueAsync(bool runOnce = false)
517499 }
518500 else
519501 {
520- await Task . Delay ( _delayForResultsUploadDequeue ) ;
502+ await Task . Delay ( _delayForSummaryUploadDequeue ) ;
521503 }
522504 }
523505 }
@@ -794,15 +776,15 @@ private async Task UploadFile(UploadFileInfo file)
794776 }
795777 }
796778
797- private async Task UploadSummaryFile ( ResultsUploadFileInfo file )
779+ private async Task UploadSummaryFile ( SummaryUploadFileInfo file )
798780 {
799781 bool uploadSucceed = false ;
800782 try
801783 {
802784 // Upload the step summary
803785 Trace . Info ( $ "Starting to upload summary file to results service { file . Name } , { file . Path } ") ;
804786 var cancellationTokenSource = new CancellationTokenSource ( ) ;
805- await _jobServer . CreateStepSummaryAsync ( file . PlanId , file . JobId , file . RecordId , file . Path , cancellationTokenSource . Token ) ;
787+ await _jobServer . CreateStepSymmaryAsync ( file . PlanId , file . JobId , file . StepId , file . Path , cancellationTokenSource . Token ) ;
806788
807789 uploadSucceed = true ;
808790 }
@@ -822,34 +804,6 @@ private async Task UploadSummaryFile(ResultsUploadFileInfo file)
822804 }
823805 }
824806 }
825-
826- private async Task UploadResultsStepLogFile ( ResultsUploadFileInfo file )
827- {
828- bool uploadSucceed = false ;
829- try
830- {
831- Trace . Info ( $ "Starting upload of step log file to results service { file . Name } , { file . Path } ") ;
832- var cancellationTokenSource = new CancellationTokenSource ( ) ;
833- await _jobServer . CreateResultsStepLogAsync ( file . PlanId , file . JobId , file . RecordId , file . Path , file . Finalize , file . FirstBlock , file . TotalLines , cancellationTokenSource . Token ) ;
834-
835- uploadSucceed = true ;
836- }
837- finally
838- {
839- if ( uploadSucceed && file . DeleteSource )
840- {
841- try
842- {
843- File . Delete ( file . Path ) ;
844- }
845- catch ( Exception ex )
846- {
847- Trace . Info ( "Exception encountered during deletion of a temporary file that was already successfully uploaded to results." ) ;
848- Trace . Error ( ex ) ;
849- }
850- }
851- }
852- }
853807 }
854808
855809 internal class PendingTimelineRecord
@@ -868,18 +822,14 @@ internal class UploadFileInfo
868822 public bool DeleteSource { get ; set ; }
869823 }
870824
871- internal class ResultsUploadFileInfo
825+ internal class SummaryUploadFileInfo
872826 {
873827 public string Name { get ; set ; }
874- public string Type { get ; set ; }
875828 public string Path { get ; set ; }
876829 public string PlanId { get ; set ; }
877830 public string JobId { get ; set ; }
878- public Guid RecordId { get ; set ; }
831+ public string StepId { get ; set ; }
879832 public bool DeleteSource { get ; set ; }
880- public bool Finalize { get ; set ; }
881- public bool FirstBlock { get ; set ; }
882- public long TotalLines { get ; set ; }
883833 }
884834
885835
0 commit comments