Skip to content

Registration

Bojan Malinić edited this page Jan 17, 2024 · 13 revisions

This project provides extension methods that register API services or handle task and workflow registration.

Conductor Client/Engine Registration

Registration example:

 services
    .AddConductorSharp(
        baseUrl: configuration.GetValue<string>("Conductor:BaseUrl"),
        apiPath: configuration.GetValue<string>("Conductor:ApiUrl"),
        preventErrorOnBadRequest: configuration.GetValue<bool>("Conductor:PreventErrorOnBadRequest")
    )
    .AddExecutionManager(
        maxConcurrentWorkers: configuration.GetValue<int>("Conductor:MaxConcurrentWorkers"),
        sleepInterval: configuration.GetValue<int>("Conductor:SleepInterval"),
        longPollInterval: configuration.GetValue<int>("Conductor:LongPollInterval"),
        domain: configuration.GetValue<string>("Conductor:WorkerDomain"),
        handlerAssemblies: typeof(Program).Assembly
    )
    .SetHealthCheckService<FileHealthService>()
    .AddPipelines(pipelines =>
    {
        pipelines.AddContextLogging();
        pipelines.AddRequestResponseLogging();
        pipelines.AddValidation();
    });

Not all methods are required. For example using execution manager (added with AddExecutionManager() method) without adding client (added with AddConductorSharp() method) is not allowed.

AddConductorSharp registers several services used to access Conductor API. The following interfaces can be requested via DI:

  • IAdminService
  • IEventService
  • IHealthService
  • IMetadataService
  • IQueueAdminService
  • IWorkflowBulkService
  • IWorkflowService
  • ITaskService

These interfaces correspond to Conductor Swagger sections.

AddExecutionManager registers a background service that will poll Conductor for tasks handled by the application and execute them concurrently. It allows us to write ITaskRequstHandler(derived from MediatR IRequestHandler) classes which correspond to task workers. Since library uses MediatR library to represent workers we must specify list of assemblies where all IRequestHandler classes are located. Tasks and workflows are registered by background service on startup.

When the application is running in a Docker/Kubernetes environment it can be useful to know if the application is healthy. This is either implemented using "health" endpoint or by testing for file existence on filesystem. Since deployment of workflows can fail due to various reasons or Conductor itself becomes unavailable library provides the ability to specify health behavior by using SetHealthCheckService method.

Library provides following implementations:

  • FileHealthService - It creates the file if deployment is successful
  • InMemoryHealthService - It sets in memory variable if deployment is successful

AddPipelines is used to add MediatR behaviors to task execution pipeline. The library provides several methods which add MediatR behaviors behind the scenes:

  • AddContextLogging() - Workflow context logging(workflow id, task id, ...)
  • AddRequestResponseLogging() - Request, response and execution time logging
  • AddValidation()- Performs validation of System.ComponentModel.DataAnnotations attributes

Task/Wokflow Registration

Registering of tasks and workflows to conductor is done by registering the workflow and worker classes to dependency injection. At runtime all the registrations are resolved and requests are made to Conductor to add the workflows and tasks.

services.RegisterWorkerTask<GetCustomerHandler>(); 
services.RegisterWorkflow<SendCustomerNotification>();

RegisterWorkerTask accepts delegate which can be used to configure task options like retry policy and timeouts.

Clone this wiki locally