3using Microsoft.Extensions.Logging;
4using Microsoft.Extensions.Logging.Abstractions;
34 readonly ILogger<JobProgressReporter>
logger;
98 this.logger =
logger ??
throw new ArgumentNullException(nameof(
logger));
99 this.callback =
callback ??
throw new ArgumentNullException(nameof(
callback));
109 logger.LogDebug(
"Job progress reporter created. Stage: {stageName}",
stageName ??
"(null)");
124 new InvalidOperationException($
"Parent progress reporter has child sections that didn't complete! Current: {sectionProgression}"),
125 "TGS BUG: Progress reporter children didn't complete!");
148 new InvalidOperationException(
"Progress reporter is reporting progress with existing nested sections!"),
149 "TGS BUG: A progress reporter is using mixed local and nested progress, this is not supported");
152 var clampedProgress = progress;
153 if (progress.HasValue)
154 if (progress > 1 || progress < 0)
157 new ArgumentOutOfRangeException(nameof(progress), progress,
"Progress must be a value from 0-1!"),
158 "TGS BUG: Invalid progress value for stage {stageName}",
160 clampedProgress =
null;
178 if (percentage > 1 || percentage < 0)
181 new ArgumentOutOfRangeException(nameof(percentage), percentage,
"Percentage must be a value from 0-1!"),
182 "TGS BUG: Invalid percentage value for stage {newStageName}! Clamping...",
183 newStageName ??
"(null)");
185 percentage = Math.Min(Math.Max(percentage, 0.0), 1.0);
193 new InvalidOperationException(
"Progress reporter is creating a section with local progress!"),
194 "TGS BUG: A progress reporter is using mixed local and nested progress, this is not supported");
205 "Stage {newStageName} is overbudgeted ({budget}/{remainingPercentage})! Clamping...",
208 remainingPercentage);
209 percentage = remainingPercentage;
214 var childLocalProgress = 0.0;
218 (currentStage, progress) =>
221 if (!progress.HasValue)
223 callback(currentStage, null);
228 childLocalProgress = progress.Value * percentage;
239 newReporter.ReportProgress(0);
Progress reporter for a Job.
double? lastProgress
The last progress value pushed into the callback.
double sectionProgression
The total progress reported so far in this section.
string? StageName
The name of the current stage.
readonly Action< string?, double?> callback
Progress reporter callback taking a description of what the job is currently doing and the (optional)...
JobProgressReporter CreateSection(string? newStageName, double percentage)
Create a subsection of the JobProgressReporter with its optional own stage name.
JobProgressReporter(ILogger< JobProgressReporter > logger, string? stageName, Action< string?, double?> callback)
Initializes a new instance of the JobProgressReporter class.
readonly ILogger< JobProgressReporter > logger
The ILogger<TCategoryName> for the JobProgressReporter.
JobProgressReporter(ILogger< JobProgressReporter > logger, string? stageName, Action< string?, double?> callback, bool setStageName)
Initializes a new instance of the JobProgressReporter class.
JobProgressReporter()
Initializes a new instance of the JobProgressReporter class.
double? sectionReservations
The total progress reserved for use in this section.
void ReportProgress(double? progress)
Report progress.
string? stageName
Backing field for StageName.
Represents an Api.Models.Instance in the database.