Skip to content

Commit

Permalink
Named record for ActivityInput
Browse files Browse the repository at this point in the history
  • Loading branch information
dstenroejl committed Dec 17, 2024
1 parent 05b218d commit d97949d
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class EnqueueMessagesActivity_Brs_026_V1(
private readonly IClock _clock = clock;
private readonly IOrchestrationInstanceProgressRepository _progressRepository = progressRepository;

public static Task RunActivity(TaskOrchestrationContext context, EnqueueMessagesActivityInput activityInput, TaskOptions options)
public static Task RunActivity(TaskOrchestrationContext context, ActivityInput activityInput, TaskOptions options)
{
return context.CallActivityAsync(
nameof(EnqueueMessagesActivity_Brs_026_V1),
Expand All @@ -41,7 +41,7 @@ public static Task RunActivity(TaskOrchestrationContext context, EnqueueMessages

[Function(nameof(EnqueueMessagesActivity_Brs_026_V1))]
public async Task Run(
[ActivityTrigger] EnqueueMessagesActivityInput input)
[ActivityTrigger] ActivityInput input)
{
var orchestrationInstance = await _progressRepository
.GetAsync(input.InstanceId)
Expand All @@ -54,13 +54,13 @@ public async Task Run(
await EnqueueMessagesAsync(input).ConfigureAwait(false);
}

private async Task EnqueueMessagesAsync(EnqueueMessagesActivityInput input)
private async Task EnqueueMessagesAsync(ActivityInput input)
{
// TODO: Enqueue message in EDI instead of delay
await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);
}

public record EnqueueMessagesActivityInput(
public record ActivityInput(
OrchestrationInstanceId InstanceId,
RequestCalculatedEnergyTimeSeriesInputV1 RequestInput);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class EnqueueRejectMessageActivity_Brs_026_V1(
private readonly IClock _clock = clock;
private readonly IOrchestrationInstanceProgressRepository _progressRepository = progressRepository;

public static Task RunActivity(TaskOrchestrationContext context, EnqueueRejectMessageActivityInput activityInput, TaskOptions options)
public static Task RunActivity(TaskOrchestrationContext context, ActivityInput activityInput, TaskOptions options)
{
return context.CallActivityAsync(
nameof(EnqueueRejectMessageActivity_Brs_026_V1),
Expand All @@ -40,7 +40,7 @@ public static Task RunActivity(TaskOrchestrationContext context, EnqueueRejectMe

[Function(nameof(EnqueueRejectMessageActivity_Brs_026_V1))]
public async Task Run(
[ActivityTrigger] EnqueueRejectMessageActivityInput input)
[ActivityTrigger] ActivityInput input)
{
var orchestrationInstance = await _progressRepository
.GetAsync(input.InstanceId)
Expand All @@ -54,13 +54,13 @@ public async Task Run(
await EnqueueRejectMessageAsync(input).ConfigureAwait(false);
}

private async Task EnqueueRejectMessageAsync(EnqueueRejectMessageActivityInput input)
private async Task EnqueueRejectMessageAsync(ActivityInput input)
{
// TODO: Enqueue message in EDI instead of delay
await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);
}

public record EnqueueRejectMessageActivityInput(
public record ActivityInput(
OrchestrationInstanceId InstanceId,
string ValidationError);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class PerformAsyncValidationActivity_Brs_026_V1(
private readonly IClock _clock = clock;
private readonly IOrchestrationInstanceProgressRepository _progressRepository = progressRepository;

public static Task<bool> RunActivity(TaskOrchestrationContext context, AsyncValidationActivityInput activityInput, TaskOptions options)
public static Task<bool> RunActivity(TaskOrchestrationContext context, ActivityInput activityInput, TaskOptions options)
{
return context.CallActivityAsync<bool>(
nameof(PerformAsyncValidationActivity_Brs_026_V1),
Expand All @@ -41,7 +41,7 @@ public static Task<bool> RunActivity(TaskOrchestrationContext context, AsyncVali

[Function(nameof(PerformAsyncValidationActivity_Brs_026_V1))]
public async Task<bool> Run(
[ActivityTrigger] AsyncValidationActivityInput input)
[ActivityTrigger] ActivityInput input)
{
var orchestrationInstance = await _progressRepository
.GetAsync(input.InstanceId)
Expand All @@ -64,7 +64,7 @@ private async Task<bool> PerformAsyncValidationAsync(RequestCalculatedEnergyTime
return true;
}

public record AsyncValidationActivityInput(
public record ActivityInput(
OrchestrationInstanceId InstanceId,
RequestCalculatedEnergyTimeSeriesInputV1 RequestInput);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,26 @@ internal class StartOrchestrationActivity_Brs_026_V1(
private readonly IClock _clock = clock;
private readonly IOrchestrationInstanceProgressRepository _progressRepository = progressRepository;

public static Task RunActivity(TaskOrchestrationContext context, OrchestrationInstanceId orchestrationId, TaskOptions options)
public static Task RunActivity(TaskOrchestrationContext context, ActivityInput input, TaskOptions options)
{
return context.CallActivityAsync(
nameof(StartOrchestrationActivity_Brs_026_V1),
orchestrationId,
input,
options);
}

[Function(nameof(StartOrchestrationActivity_Brs_026_V1))]
public async Task Run(
[ActivityTrigger] OrchestrationInstanceId orchestrationInstanceId)
[ActivityTrigger] ActivityInput input)
{
var orchestrationInstance = await _progressRepository
.GetAsync(orchestrationInstanceId)
.GetAsync(input.InstanceId)
.ConfigureAwait(false);

orchestrationInstance.Lifecycle.TransitionToRunning(_clock);
await _progressRepository.UnitOfWork.CommitAsync().ConfigureAwait(false);
}

public record ActivityInput(
OrchestrationInstanceId InstanceId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class TerminateOrchestrationActivity_Brs_026_V1(
private readonly IClock _clock = clock;
private readonly IOrchestrationInstanceProgressRepository _progressRepository = progressRepository;

public static Task RunActivity(TaskOrchestrationContext context, TerminateOrchestrationActivityInput input, TaskOptions options)
public static Task RunActivity(TaskOrchestrationContext context, ActivityInput input, TaskOptions options)
{
return context.CallActivityAsync(
nameof(TerminateOrchestrationActivity_Brs_026_V1),
Expand All @@ -40,7 +40,7 @@ public static Task RunActivity(TaskOrchestrationContext context, TerminateOrches

[Function(nameof(TerminateOrchestrationActivity_Brs_026_V1))]
public async Task Run(
[ActivityTrigger] TerminateOrchestrationActivityInput input)
[ActivityTrigger] ActivityInput input)
{
var orchestrationInstance = await _progressRepository
.GetAsync(input.InstanceId)
Expand All @@ -64,7 +64,7 @@ public async Task Run(
await _progressRepository.UnitOfWork.CommitAsync().ConfigureAwait(false);
}

public record TerminateOrchestrationActivityInput(
public record ActivityInput(
OrchestrationInstanceId InstanceId,
OrchestrationInstanceTerminationStates TerminationState);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class TerminateStepActivity_Brs_026_V1(
private readonly IClock _clock = clock;
private readonly IOrchestrationInstanceProgressRepository _progressRepository = progressRepository;

public static Task RunActivity(TaskOrchestrationContext context, TerminateStepActivityInput input, TaskOptions options)
public static Task RunActivity(TaskOrchestrationContext context, ActivityInput input, TaskOptions options)
{
return context.CallActivityAsync(
nameof(TerminateStepActivity_Brs_026_V1),
Expand All @@ -40,7 +40,7 @@ public static Task RunActivity(TaskOrchestrationContext context, TerminateStepAc

[Function(nameof(TerminateStepActivity_Brs_026_V1))]
public async Task Run(
[ActivityTrigger] TerminateStepActivityInput input)
[ActivityTrigger] ActivityInput input)
{
var orchestrationInstance = await _progressRepository
.GetAsync(input.InstanceId)
Expand All @@ -54,7 +54,7 @@ public async Task Run(
await _progressRepository.UnitOfWork.CommitAsync().ConfigureAwait(false);
}

public record TerminateStepActivityInput(
public record ActivityInput(
OrchestrationInstanceId InstanceId,
int StepSequence,
OrchestrationStepTerminationStates TerminationState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,19 @@ public async Task<string> Run(
var defaultRetryOptions = CreateDefaultRetryOptions();

// Set orchestration lifecycle to running
await StartOrchestrationActivity_Brs_026_V1.RunActivity(context, instanceId, defaultRetryOptions);
await StartOrchestrationActivity_Brs_026_V1.RunActivity(
context,
new StartOrchestrationActivity_Brs_026_V1.ActivityInput(
instanceId),
defaultRetryOptions);

var isValid = await PerformAsyncValidation(context, instanceId, input, defaultRetryOptions);

if (isValid)
{
await EnqueueMessagesActivity_Brs_026_V1.RunActivity(
context,
new EnqueueMessagesActivity_Brs_026_V1.EnqueueMessagesActivityInput(
new EnqueueMessagesActivity_Brs_026_V1.ActivityInput(
instanceId,
input),
defaultRetryOptions);
Expand All @@ -67,7 +71,7 @@ await EnqueueMessagesActivity_Brs_026_V1.RunActivity(
{
await EnqueueRejectMessageActivity_Brs_026_V1.RunActivity(
context,
new EnqueueRejectMessageActivity_Brs_026_V1.EnqueueRejectMessageActivityInput(
new EnqueueRejectMessageActivity_Brs_026_V1.ActivityInput(
instanceId,
"Validation error"),
defaultRetryOptions);
Expand All @@ -80,7 +84,7 @@ await EnqueueRejectMessageActivity_Brs_026_V1.RunActivity(
: OrchestrationStepTerminationStates.Failed;
await TerminateStepActivity_Brs_026_V1.RunActivity(
context,
new TerminateStepActivity_Brs_026_V1.TerminateStepActivityInput(
new TerminateStepActivity_Brs_026_V1.ActivityInput(
instanceId,
EnqueueMessagesStepSequence,
enqueueMessagesTerminationState),
Expand All @@ -96,7 +100,7 @@ await TerminateStepActivity_Brs_026_V1.RunActivity(

await TerminateOrchestrationActivity_Brs_026_V1.RunActivity(
context,
new TerminateOrchestrationActivity_Brs_026_V1.TerminateOrchestrationActivityInput(
new TerminateOrchestrationActivity_Brs_026_V1.ActivityInput(
instanceId,
OrchestrationInstanceTerminationStates.Failed),
defaultRetryOptions);
Expand All @@ -106,7 +110,7 @@ await TerminateOrchestrationActivity_Brs_026_V1.RunActivity(

await TerminateOrchestrationActivity_Brs_026_V1.RunActivity(
context,
new TerminateOrchestrationActivity_Brs_026_V1.TerminateOrchestrationActivityInput(
new TerminateOrchestrationActivity_Brs_026_V1.ActivityInput(
instanceId,
OrchestrationInstanceTerminationStates.Succeeded),
defaultRetryOptions);
Expand All @@ -131,7 +135,7 @@ private async Task<bool> PerformAsyncValidation(
{
var isValid = await PerformAsyncValidationActivity_Brs_026_V1.RunActivity(
context,
new PerformAsyncValidationActivity_Brs_026_V1.AsyncValidationActivityInput(
new PerformAsyncValidationActivity_Brs_026_V1.ActivityInput(
instanceId,
input),
retryOptions);
Expand All @@ -141,7 +145,7 @@ private async Task<bool> PerformAsyncValidation(
: OrchestrationStepTerminationStates.Failed;
await TerminateStepActivity_Brs_026_V1.RunActivity(
context,
new TerminateStepActivity_Brs_026_V1.TerminateStepActivityInput(
new TerminateStepActivity_Brs_026_V1.ActivityInput(
instanceId,
AsyncValidationStepSequence,
asyncValidationTerminationState),
Expand Down

0 comments on commit d97949d

Please sign in to comment.