Skip to content

jokecamp/conductor-dotnet-client

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

conductor-dotnet-client

This packages provides both an abstration for the Conductor REST API and a way to start a worker that polls for certain tasks.

The REST API client is based on the swagger.json file as provided by Conductor. The client is generated with NSwag and the nswag.json config and swagger data is provided in the repo.

Client usage

Register the client in your DI with the following method:

services.AddConductorClient( service => "http://localhost:8080/api/");

To use the generated REST API ask for the IConductorRestClient interface.

public Sample
{
    public Sample(IConductorRestClient conductorRestClient)
    {
        var workflowInstanceId = conductorRestClient.StartWorkflowAsync(startWorkflowRequest).GetAwaiter().GetResult()
    }
}

Worker usage

To use the worker register the client and worker in your DI with the following method, you have the option to set the amount of workers, polling interval, interval stragtegy, max interval time and domain.

services.AddConductorWorker(new ConductorClientSettings()
{
    ConcurrentWorkers = 1,
    Domain = "SampleDomain",
    IntervalStrategy = ConductorClientSettings.IntervalStrategyType.Linear,
    MaxSleepInterval = 15_000,
    SleepInterval = 1_000,
    ServerUrl = new Uri("http://localhost:8080/api/")
})

This will start x workes who will poll every y second for new tasks. If no task is returned it will back off based on the strategy provided.

Your worker has to implement the IWorkflowTask interface;

public class SampleWorker : IWorkflowTask
{
    public string TaskType { get; } = "test_task"; 
    public int? Priority { get; } = 1;

    public Task<TaskResult> Execute(ConductorTask task)
    {
        Console.WriteLine("Doing some work");
        return Task.FromResult(task.Completed());
        //return Task.FromResult(task.Completed(new Dictionary<string, object>() { })); // with ouputdata
        //return Task.FromResult(task.Failed("error message ")); //error
        //return Task.FromResult(task.FailedWithTerminalError("error message")); // terminal failure
    }
}

Priority polling

Priority pollings works as follow, the higher the number the earlier the task will be polled:

    public int? Priority { get; } = 1;

And all null priorities will be randomized.

    public int? Priority { get; } = null;

You can use both at the same time.

Registering

Be registerd in the DI;

services.AddConductorWorkflowTask<SampleWorkerTask>();

And also be regsiterd with the worker:

var workflowTaskCoordinator = serviceProvider.GetRequiredService<IWorkflowTaskCoordinator>();
foreach(var worker in serviceProvider.GetServices<IWorkflowTask>())
{
    workflowTaskCoordinator.RegisterWorker(worker);
}

After that you can start the worker:

await workflowTaskCoordinator.Start();

Make sure to await it as it is an never ending task.

Installation

Install-Package ConductorDotnetClient

TODO

  • Shutdown
  • Implement response timeout ping

About

Dotnet standard client for Netflix Conductor

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%