-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/expressions-python-sdk
- Loading branch information
Showing
14 changed files
with
321 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,4 +46,6 @@ dist/ | |
|
||
# dotnet | ||
global.json | ||
*DotSettings.user | ||
*DotSettings.user | ||
!sdk-dotnet/Littlehorse.sln | ||
*.sln |
14 changes: 14 additions & 0 deletions
14
sdk-dotnet/Examples/ExceptionsHandlerExample/ExceptionsHandlerExample.csproj
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,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\LittleHorse.Sdk\LittleHorse.Sdk.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,70 @@ | ||
using ExceptionsHandler; | ||
using LittleHorse.Sdk; | ||
using LittleHorse.Sdk.Worker; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace ExceptionsHandlerExample; | ||
|
||
public abstract class Program | ||
{ | ||
private static ServiceProvider? _serviceProvider; | ||
|
||
private static void SetupApplication() | ||
{ | ||
_serviceProvider = new ServiceCollection() | ||
.AddLogging(config => | ||
{ | ||
config.AddConsole(); | ||
config.SetMinimumLevel(LogLevel.Debug); | ||
}) | ||
.BuildServiceProvider(); | ||
} | ||
|
||
private static LHConfig GetLHConfig(string[] args, ILoggerFactory loggerFactory) | ||
{ | ||
var config = new LHConfig(loggerFactory); | ||
|
||
string filePath = Path.Combine(Directory.GetCurrentDirectory(), ".config/littlehorse.config"); | ||
if (File.Exists(filePath)) | ||
config = new LHConfig(filePath, loggerFactory); | ||
|
||
return config; | ||
} | ||
|
||
private static List<LHTaskWorker<MyWorker>> GetTaskWorkers(LHConfig config) | ||
{ | ||
MyWorker executableExceptionHandling = new MyWorker(); | ||
var workers = new List<LHTaskWorker<MyWorker>> | ||
{ | ||
new(executableExceptionHandling, "fail", config), | ||
new(executableExceptionHandling, "fail-new-process", config), | ||
new(executableExceptionHandling, "technical-failure", config), | ||
new(executableExceptionHandling, "my-task", config) | ||
}; | ||
|
||
return workers; | ||
} | ||
|
||
static void Main(string[] args) | ||
{ | ||
SetupApplication(); | ||
if (_serviceProvider != null) | ||
{ | ||
var loggerFactory = _serviceProvider.GetRequiredService<ILoggerFactory>(); | ||
var config = GetLHConfig(args, loggerFactory); | ||
var workers = GetTaskWorkers(config); | ||
foreach (var worker in workers) | ||
{ | ||
worker.RegisterTaskDef(); | ||
} | ||
|
||
Thread.Sleep(300); | ||
|
||
foreach (var worker in workers) | ||
{ | ||
worker.Start(); | ||
} | ||
} | ||
} | ||
} |
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,31 @@ | ||
## Running Exceptions Handler Example | ||
|
||
This is a simple demonstration of a workflow that handles the failure of a task with | ||
the handleException() functionality, which spawns a child thread and then | ||
resumes execution when the handler thread completes. | ||
|
||
Let's run the example in `ExceptionsHandlerExample` | ||
|
||
``` | ||
dotnet build | ||
dotnet run | ||
``` | ||
|
||
In another terminal, use `lhctl` to run the workflow: | ||
|
||
``` | ||
lhctl run example-exception-handler | ||
``` | ||
|
||
In addition, you can check the result with: | ||
|
||
``` | ||
# This call shows the result | ||
lhctl get wfRun <wf_run_id> | ||
# This will show you all nodes in tha run | ||
lhctl list nodeRun <wf_run_id> | ||
# This shows the task run information | ||
lhctl get taskRun <wf_run_id> <task_run_global_id> | ||
``` |
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,56 @@ | ||
using LittleHorse.Common.Proto; | ||
using LittleHorse.Sdk.Worker; | ||
using LHTaskException = LittleHorse.Sdk.Exceptions.LHTaskException; | ||
|
||
namespace ExceptionsHandler | ||
{ | ||
public class MyWorker | ||
{ | ||
[LHTaskMethod("fail")] | ||
public void Fail() | ||
{ | ||
Random random = new Random(); | ||
int randomNumber = random.Next(6, 10); | ||
var message = $"Throw New Failing Task {randomNumber}."; | ||
if (randomNumber > 5) | ||
{ | ||
throw new LHTaskException("Fail", message); | ||
} | ||
|
||
Console.WriteLine(message); | ||
} | ||
|
||
[LHTaskMethod("fail-new-process")] | ||
public void FailNewProcess() | ||
{ | ||
Random random = new Random(); | ||
int randomNumber = random.Next(1, 10); | ||
var message = $"Throw Other Failing Task {randomNumber}"; | ||
if (randomNumber < 8) | ||
{ | ||
VariableValue content = new VariableValue | ||
{ | ||
Str = "This is a problem" | ||
}; | ||
throw new LHTaskException("Fail-New-Task", message, content); | ||
} | ||
|
||
Console.WriteLine(message); | ||
} | ||
|
||
[LHTaskMethod("technical-failure")] | ||
public void FailForTechnicalReason() | ||
{ | ||
String message = null!; | ||
int result = message.Length; | ||
Console.WriteLine(result); | ||
} | ||
|
||
[LHTaskMethod("my-task")] | ||
public string PassingTask() | ||
{ | ||
Console.WriteLine("Executing passing task."); | ||
return "woohoo!"; | ||
} | ||
} | ||
} |
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
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,22 @@ | ||
using LittleHorse.Common.Proto; | ||
|
||
namespace LittleHorse.Sdk.Exceptions; | ||
|
||
public class LHTaskException: Exception | ||
{ | ||
public string Name { get; } | ||
|
||
public VariableValue Content { get; } | ||
|
||
public LHTaskException(String name, String message): base(message) | ||
{ | ||
Name = name; | ||
Content = new VariableValue(); | ||
} | ||
|
||
public LHTaskException(String name, String message, VariableValue content): base(message) | ||
{ | ||
Name = name; | ||
Content = content; | ||
} | ||
} |
Oops, something went wrong.