Skip to content

Commit

Permalink
feat: Recurring orchestrations (#36)
Browse files Browse the repository at this point in the history
* Grpc.tools

* Remove client dependency

* Cleanup after temp trigger

* Modify test

* Add general recurring trigger

* Refactor names

* Refactor test

* Grps.Tools

* Support RecurringCronExpression

* Move

* Fix build

* Fix build

* Order scripts

* Pseudo code

* GetAllRecurringAsync

* Recurring query

* Comment

* Docs

* Prepare for testing handler

* RecurringOrchestrationQueries

* Fix test

* Grpc

* Fix markdown

* Do not use _sut to add data

* SearchScheduledOrchestrationInstancesAsync

* DI registration

* Remove use of ProcessManagerCoreCollection

* Test

* Plan

* Test using mock

* Dispose

* Dispose

* Removed comment

* Test

* Cleanup

* Simplify convertion to instant

* Refactor to use user identity for scheduling recurring jobs

* Update source/ProcessManager/Scheduler/RecurringPlannerHandler.cs

Co-authored-by: Ebbe Knudsen <[email protected]>

---------

Co-authored-by: Ebbe Knudsen <[email protected]>
  • Loading branch information
dstenroejl and ebbeknudsen authored Dec 12, 2024
1 parent 2fd781a commit 63d5a46
Show file tree
Hide file tree
Showing 27 changed files with 972 additions and 172 deletions.
9 changes: 9 additions & 0 deletions docs/ProcessManager/Development.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

// TODO: This ducoment should be split into multiple; this is just a placeholder for relevant subjects that should be documented.

## Active feature flags

We use TimerTrigger [built in functionality](https://learn.microsoft.com/en-us/azure/azure-functions/disable-function?tabs=portal) to disable them in preproduction and production.

The TimerTriggers are:

- `StartScheduledOrchestrationInstances`
- `PerformRecurringPlanning`

## Organization of artifacts

// TODO: Describe organization in repository -> files/folders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ public async Task RequestCalculatedEnergyTimeSeries_WhenStarted_OrchestrationCom

var processManagerMessageClient = ServiceProvider.GetRequiredService<IProcessManagerMessageClient>();

var orchestrationCreatedAfter = DateTime.UtcNow.AddSeconds(-5);
var orchestrationCreatedAfter = DateTime.UtcNow.AddSeconds(-1);
await processManagerMessageClient.StartNewOrchestrationInstanceAsync(startRequestCommand, default);

// Assert
var orchestration = await _fixture.DurableClient.WaitForOrchestationStartedAsync(
orchestrationCreatedAfter,
createdTimeFrom: orchestrationCreatedAfter,
name: "RequestCalculatedEnergyTimeSeriesOrchestrationV1");
orchestration.Input.ToString().Should().Contain(businessReason);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

namespace Energinet.DataHub.ProcessManager.Core.Tests.Integration.Infrastructure.Database;

[Collection(nameof(ProcessManagerCoreCollection))]
public class ProcessManagerContextTests
public class ProcessManagerContextTests : IClassFixture<ProcessManagerCoreFixture>
{
private readonly ProcessManagerCoreFixture _fixture;

Expand Down Expand Up @@ -54,6 +53,29 @@ public async Task Given_OrchestrationDescriptionAddedToDbContext_WhenRetrievingF
.BeEquivalentTo(existingOrchestrationDescription);
}

[Fact]
public async Task Given_RecurringOrchestrationDescriptionAddedToDbContext_WhenRetrievingFromDatabase_HasCorrectValues()
{
// Arrange
var existingOrchestrationDescription = CreateOrchestrationDescription(recurringCronExpression: "0 0 * * *");

await using (var writeDbContext = _fixture.DatabaseManager.CreateDbContext())
{
writeDbContext.OrchestrationDescriptions.Add(existingOrchestrationDescription);
await writeDbContext.SaveChangesAsync();
}

// Act
await using var readDbContext = _fixture.DatabaseManager.CreateDbContext();
var orchestrationDescription = await readDbContext.OrchestrationDescriptions.FindAsync(existingOrchestrationDescription.Id);

// Assert
orchestrationDescription.Should()
.NotBeNull()
.And
.BeEquivalentTo(existingOrchestrationDescription);
}

[Fact]
public async Task Given_OrchestrationInstanceWithStepsAddedToDbContext_WhenRetrievingFromDatabase_HasCorrectValues()
{
Expand Down Expand Up @@ -136,13 +158,16 @@ public async Task Given_UserCanceledOrchestrationInstanceAddedToDbContext_WhenRe
.BeEquivalentTo(existingOrchestrationInstance);
}

private static OrchestrationDescription CreateOrchestrationDescription()
private static OrchestrationDescription CreateOrchestrationDescription(string? recurringCronExpression = default)
{
var orchestrationDescription = new OrchestrationDescription(
uniqueName: new OrchestrationDescriptionUniqueName("TestOrchestration", 4),
canBeScheduled: true,
functionName: "TestOrchestrationFunction");

if (recurringCronExpression != null)
orchestrationDescription.RecurringCronExpression = recurringCronExpression;

orchestrationDescription.ParameterDefinition.SetFromType<TestOrchestrationParameter>();

orchestrationDescription.AppendStepDescription("Test step 1");
Expand Down
Loading

0 comments on commit 63d5a46

Please sign in to comment.