Skip to content

Latest commit

 

History

History
37 lines (31 loc) · 1.22 KB

README.md

File metadata and controls

37 lines (31 loc) · 1.22 KB

Camunda.Worker

codecov NuGet

Example

[HandlerTopics("sayHello", LockDuration = 10_000)]
[HandlerVariables("USERNAME")]
public class SayHelloHandler : IExternalTaskHandler
{
    public async Task<IExecutionResult> HandleAsync(ExternalTask externalTask, CancellationToken cancellationToken)
    {
        if (!externalTask.TryGetVariable<StringVariable>("USERNAME", out var usernameVariable))
        {
            return new BpmnErrorResult("NO_USER", "Username not provided");
        }

        var username = usernameVariable.Value;

        await Task.Delay(1000, cancellationToken);

        return new CompleteResult
        {
            Variables = new Dictionary<string, VariableBase>
            {
                ["MESSAGE"] = new StringVariable($"Hello, {username}!"),
                ["USER_INFO"] = JsonVariable.Create(new UserInfo(username, new List<string>
                {
                    "Admin"
                }))
            }
        };
    }
}