diff --git a/sdk-dotnet/Examples/WorkerContextExample/MyWorker.cs b/sdk-dotnet/Examples/WorkerContextExample/MyWorker.cs index 7b1f03f28..5ba11992a 100644 --- a/sdk-dotnet/Examples/WorkerContextExample/MyWorker.cs +++ b/sdk-dotnet/Examples/WorkerContextExample/MyWorker.cs @@ -4,8 +4,8 @@ namespace WorkerContextExample; public class MyWorker { - [LHTaskMethod("process-payment")] - public void ProcessPayment(LHWorkerContext context) + [LHTaskMethod("task")] + public void ProcessTask(LHWorkerContext context) { context.Log("ProcessPayment"); Console.WriteLine($"The Workflow Run Id is: {context.GetWfRunId()}"); diff --git a/sdk-dotnet/Examples/WorkerContextExample/Program.cs b/sdk-dotnet/Examples/WorkerContextExample/Program.cs index 322fe5c5f..880850a0a 100644 --- a/sdk-dotnet/Examples/WorkerContextExample/Program.cs +++ b/sdk-dotnet/Examples/WorkerContextExample/Program.cs @@ -35,7 +35,7 @@ private static List> GetTaskWorkers(LHConfig config) MyWorker executableExceptionHandling = new MyWorker(); var workers = new List> { - new(executableExceptionHandling, "process-payment", config) + new(executableExceptionHandling, "task", config) }; return workers; diff --git a/sdk-dotnet/Examples/WorkerContextExample/README.md b/sdk-dotnet/Examples/WorkerContextExample/README.md new file mode 100644 index 000000000..eb5e0ac7b --- /dev/null +++ b/sdk-dotnet/Examples/WorkerContextExample/README.md @@ -0,0 +1,45 @@ +## Running WorkerContextExample + +This example shows how to get access to the context when executing a task. +Go to the class `MyWorker`. + +Let's run the example in `WorkerContextExample` + +``` +dotnet build +dotnet run +``` + +In another terminal, use `lhctl` to run the workflow: + +``` +lhctl run example-worker-context +``` + +In addition, you can check the result with: + +``` +# This call shows the result +lhctl get wfRun + +# This will show you all nodes in tha run +lhctl list nodeRun + +# This shows the task run information +lhctl get taskRun +``` + +## Considerations + +If you need get access to the context you have to add a `LHWorkerContext` +parameter to the signature of your task: + +``` + [LHTaskMethod("task")] + public void ProcessTask(LHWorkerContext context) + { + ... + } +``` + +The `WorkerContext` should be the last parameter. \ No newline at end of file