Skip to content

Commit

Permalink
feat(dotnet-sdk): add readme file in example
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlaCarvajal committed Dec 2, 2024
1 parent a6e0704 commit 1cabe89
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
4 changes: 2 additions & 2 deletions sdk-dotnet/Examples/WorkerContextExample/MyWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()}");
Expand Down
2 changes: 1 addition & 1 deletion sdk-dotnet/Examples/WorkerContextExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private static List<LHTaskWorker<MyWorker>> GetTaskWorkers(LHConfig config)
MyWorker executableExceptionHandling = new MyWorker();
var workers = new List<LHTaskWorker<MyWorker>>
{
new(executableExceptionHandling, "process-payment", config)
new(executableExceptionHandling, "task", config)
};

return workers;
Expand Down
45 changes: 45 additions & 0 deletions sdk-dotnet/Examples/WorkerContextExample/README.md
Original file line number Diff line number Diff line change
@@ -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 <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>
```

## 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.

0 comments on commit 1cabe89

Please sign in to comment.