-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
describe various integration patterns
- Loading branch information
Showing
4 changed files
with
263 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
namespace MicroWorkflow; | ||
|
||
/// <summary> | ||
/// not real tests just a place for code used in the readme.md | ||
/// </summary> | ||
class DocumentationTests | ||
{ | ||
[StepName(Name)] | ||
class SendMemberEnrollmentToAcmeCompany(HttpClient client) : IStepImplementation | ||
{ | ||
public const string Name = "v1/send-member-enrollment-to-acme-company"; | ||
|
||
public async Task<ExecutionResult> ExecuteAsync(Step step) | ||
{ | ||
var result = await client.PostAsync("...", null); | ||
result.EnsureSuccessStatusCode(); | ||
return step.Done(); | ||
} | ||
} | ||
|
||
[StepName(Name)] | ||
class SendMemberEnrollmentToAcmeCompanyLimitedRetry(HttpClient client) : IStepImplementation | ||
{ | ||
public const string Name = "v1/send-member-enrollment-to-acme-company-limited-retry"; | ||
|
||
public async Task<ExecutionResult> ExecuteAsync(Step step) | ||
{ | ||
if (step.ExecutionCount > 5) | ||
return step.Fail("too many retries"); | ||
|
||
var result = await client.PostAsync("...", null); | ||
|
||
switch ((int)result.StatusCode) | ||
{ | ||
case >= 200 and < 300: | ||
return step.Done(); | ||
|
||
case >= 400 and < 500: | ||
return step.Fail("Wrong payload " + result.ToString()); | ||
|
||
case >= 500: | ||
return step.Rerun(description: $"Upstream error {result}"); | ||
|
||
default: throw new NotImplementedException(); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
[StepName(Name)] | ||
class SendMemberEnrollmentToAcmeCompanyLimitedTimewindow() : IStepImplementation | ||
{ | ||
public const string Name = "v1/send-member-enrollment-to-acme-company-limited-from-0700-to-2000"; | ||
|
||
public async Task<ExecutionResult> ExecuteAsync(Step step) | ||
{ | ||
// ensure window of 0700 - 2000 | ||
var now = DateTime.Now; | ||
if (now.Hour < 7) | ||
return step.Rerun(scheduleTime: now.Date.AddHours(7)); | ||
|
||
if (now.Hour >= 20) | ||
return step.Rerun(scheduleTime: now.Date.AddDays(1).AddHours(7)); | ||
|
||
// ... | ||
|
||
return step.Done(); | ||
} | ||
} | ||
|
||
|
||
[StepName(Name)] | ||
class ScheduledFetchDataOnceAnHour() : IStepImplementation | ||
{ | ||
public const string Name = "v1/fetch-data-from-acme-once-an-hour"; | ||
|
||
public async Task<ExecutionResult> ExecuteAsync(Step step) | ||
{ | ||
if (!step.Singleton) | ||
throw new FailCurrentStepException("Must be a singleton step!"); | ||
|
||
// ... fetch data | ||
|
||
return step.Rerun(scheduleTime: step.ExecutionStartTime!.Value.AddHours(1)); | ||
} | ||
} | ||
|
||
|
||
class AddScheduler | ||
{ | ||
public void ScheduleDataFetch(WorkflowEngine engine) | ||
{ | ||
var step = new Step(ScheduledFetchDataOnceAnHour.Name) | ||
{ | ||
Singleton = true, | ||
ScheduleTime = DateTime.Now.Date.AddHours(DateTime.Now.Hour) | ||
}; | ||
|
||
engine.Data.AddStepIfNotExists(step, new SearchModel(Name: ScheduledFetchDataOnceAnHour.Name)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters