-
Notifications
You must be signed in to change notification settings - Fork 4
Writing task handlers
Bojan Malinić edited this page Jan 17, 2024
·
1 revision
Task handlers correspond to Conductor task definitions. ConductorSharp background service periodically polls the Conductor for the new tasks and executes task handler corresponding to task in workflow.
Task handlers are written by implementing ITaskRequestHandler<TRequest, TResponse> interface.
[OriginalName("CUSTOMER_get")]
public class GetCustomerHandler : ITaskRequestHandler<GetCustomerRequest, GetCustomerResponse>
{
private static Customer[] customers = new Customer[]
{
new Customer
{
Id = 1,
Address = "Baker Street 221b",
Name = "Sherlock Holmes"
}
};
public Task<GetCustomerResponse> Handle(GetCustomerRequest request, CancellationToken cancellationToken)
{
var customer = customers.First(a => a.Id == request.CustomerId);
return Task.FromResult(new GetCustomerResponse { Name = customer.Name, Address = customer.Address });
}
}Task names are generated from class names, or using the OriginalName custom attribute.
In order for task handler to be invoked by background service first it must be registered in DI container
services.RegisterWorkerTask<GetCustomerHandler>();RegisterWorkerTask() accepts delegate which can be used to configure task options like retry policy and timeouts