Skip to content

Commit

Permalink
Add new job params
Browse files Browse the repository at this point in the history
  • Loading branch information
FirestarJes committed Sep 25, 2024
1 parent a68e101 commit be7f0df
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ public sealed record RequestSettlementReportCommand(
Guid UserId,
Guid ActorId,
bool IsFas,
string? ChargeOwnerId,
string ActorGln,
MarketRole MarketRole);
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public RequestSettlementReportHandler(
public async Task<JobRunId> HandleAsync(RequestSettlementReportCommand request)
{
var reportId = new SettlementReportRequestId(Guid.NewGuid().ToString());
var runId = await _jobHelper.RunSettlementReportsJobAsync(request.RequestDto, request.MarketRole, reportId).ConfigureAwait(false);
var runId = await _jobHelper.RunSettlementReportsJobAsync(request.RequestDto, request.MarketRole, reportId, request.ActorGln).ConfigureAwait(false);
await _settlementReportInitializeHandler
.InitializeFromJobAsync(
request.UserId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ public DatabricksJobsHelper(IJobsApiClient jobsApiClient)
public async Task<JobRunId> RunSettlementReportsJobAsync(
SettlementReportRequestDto request,
MarketRole marketRole,
SettlementReportRequestId reportId)
SettlementReportRequestId reportId,
string actorGln)
{
var job = await GetSettlementReportsJobAsync(GetJobName(request.Filter.CalculationType)).ConfigureAwait(false);
return new JobRunId(await _jobsApiClient.Jobs.RunNow(job.JobId, CreateParameters(request, marketRole, reportId)).ConfigureAwait(false));
return new JobRunId(await _jobsApiClient.Jobs.RunNow(job.JobId, CreateParameters(request, marketRole, reportId, actorGln)).ConfigureAwait(false));
}

public async Task<JobRunStatus> GetSettlementReportsJobStatusAsync(long runId)
Expand Down Expand Up @@ -71,36 +72,36 @@ private async Task<Job> GetSettlementReportsJobAsync(string jobName)
return await _jobsApiClient.Jobs.Get(settlementJob.JobId).ConfigureAwait(false);
}

private RunParameters CreateParameters(SettlementReportRequestDto request, MarketRole marketRole, SettlementReportRequestId reportId)
private RunParameters CreateParameters(SettlementReportRequestDto request, MarketRole marketRole, SettlementReportRequestId reportId, string actorGln)
{
var gridAreas = $"{{{string.Join(", ", request.Filter.GridAreas.Select(c => $"\"{c.Key}\": \"{(c.Value is null ? string.Empty : c.Value?.Id)}\""))}}}";

var jobParameters = new Dictionary<string, string>()
var jobParameters = new List<string>
{
{ "report-id", reportId.Id },
{ "calculation-type", CalculationTypeMapper.ToDeltaTableValue(request.Filter.CalculationType) },
{ "calculation-id-by-grid-area", gridAreas },
{ "period-start", request.Filter.PeriodStart.ToInstant().ToString() },
{ "period-end", request.Filter.PeriodEnd.ToInstant().ToString() },
{ "market-role", MapMarketRole(marketRole) },
$"--report-id={reportId.Id}",
$"--calculation-type={CalculationTypeMapper.ToDeltaTableValue(request.Filter.CalculationType)}",
$"--calculation-id-by-grid-area={gridAreas}",
$"--period-start={request.Filter.PeriodStart.ToInstant()}",
$"--period-end={request.Filter.PeriodEnd.ToInstant()}",
$"--requesting-actor-market-role={MapMarketRole(request.MarketRoleOverride ?? marketRole)}",
$"--requesting-actor-id={actorGln}",
};

if (request.Filter.EnergySupplier != null)
{
jobParameters.Add("energy-supplier-id", request.Filter.EnergySupplier);
jobParameters.Add($"--energy-supplier-id={request.Filter.EnergySupplier}");
}

if (request.SplitReportPerGridArea)
{
jobParameters.Add("split-report-by-grid-area", request.SplitReportPerGridArea.ToString());
jobParameters.Add("--split-report-by-grid-area");
}

if (request.PreventLargeTextFiles)
{
jobParameters.Add("prevent-large-text-files", request.PreventLargeTextFiles.ToString());
jobParameters.Add("--prevent-large-text-files");
}

return RunParameters.CreateJobParams(jobParameters);
return RunParameters.CreatePythonParams(jobParameters);
}

private static string MapMarketRole(MarketRole marketRole)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public interface IDatabricksJobsHelper
Task<JobRunId> RunSettlementReportsJobAsync(
SettlementReportRequestDto request,
MarketRole marketRole,
SettlementReportRequestId reportId);
SettlementReportRequestId reportId,
string actorGln);

Task<JobRunStatus> GetSettlementReportsJobStatusAsync(long runId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public async Task Handle_ValidRequest_ReturnsJobId()
var jobHelperMock = new Mock<IDatabricksJobsHelper>();
var jobRunId = new JobRunId(Random.Shared.NextInt64());
jobHelperMock
.Setup(x => x.RunSettlementReportsJobAsync(It.IsAny<SettlementReportRequestDto>(), It.IsAny<MarketRole>(), It.IsAny<SettlementReportRequestId>()))
.Setup(x => x.RunSettlementReportsJobAsync(It.IsAny<SettlementReportRequestDto>(), It.IsAny<MarketRole>(), It.IsAny<SettlementReportRequestId>(), It.IsAny<string>()))
.ReturnsAsync(jobRunId);

var command = new RequestSettlementReportCommand(request, Guid.NewGuid(), Guid.NewGuid(), true, null, MarketRole.EnergySupplier);
var command = new RequestSettlementReportCommand(request, Guid.NewGuid(), Guid.NewGuid(), true, "1233", MarketRole.EnergySupplier);
var handler = new RequestSettlementReportHandler(jobHelperMock.Object, initializerMock.Object);

// Act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,12 @@ public async Task<ActionResult<long>> RequestSettlementReport([FromBody] Settlem
return BadRequest();
}

var chargeOwnerId = marketRole is MarketRole.GridAccessProvider or MarketRole.SystemOperator
? _userContext.CurrentUser.Actor.ActorNumber
: null;

var requestCommand = new RequestSettlementReportCommand(
settlementReportRequest,
_userContext.CurrentUser.UserId,
_userContext.CurrentUser.Actor.ActorId,
_userContext.CurrentUser.MultiTenancy,
chargeOwnerId,
_userContext.CurrentUser.Actor.ActorNumber,
marketRole);

var result = await _requestSettlementReportJobHandler.HandleAsync(requestCommand).ConfigureAwait(false);
Expand Down

0 comments on commit be7f0df

Please sign in to comment.