Skip to content

Commit

Permalink
Merge pull request #62 from conductor-sdk/docs-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
gardusig authored Mar 23, 2023
2 parents ce7050e + 67dfb33 commit b5ec858
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 61 deletions.
13 changes: 13 additions & 0 deletions Conductor/Client/Extensions/DependencyInjectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ public static IServiceCollection AddConductorWorkflowTask<T>(this IServiceCollec
return services;
}

public static IServiceCollection AddConductorWorkflowTask<T>(this IServiceCollection services, T worker) where T : IWorkflowTask
{
services.AddTransient(typeof(IWorkflowTask), typeof(T));
services.AddTransient(typeof(T));
return services;
}

public static IServiceCollection AddConductorWorker(this IServiceCollection services, Configuration configuration = null, Action<IServiceProvider, HttpClient> configureHttpClient = null)
{
services.AddHttpClient();
Expand All @@ -35,5 +42,11 @@ public static IServiceCollection WithHostedService<T>(this IServiceCollection se
services.AddHostedService<T>();
return services;
}

public static IServiceCollection WithHostedService(this IServiceCollection services)
{
services.AddHostedService<WorkflowTaskService>();
return services;
}
}
}
32 changes: 32 additions & 0 deletions Conductor/Client/Worker/WorkflowTaskHost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Conductor.Client.Extensions;
using Conductor.Client.Interfaces;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace Conductor.Client.Worker
{
public static class WorkflowTaskHost
{
public static IHost CreateWorkerHost<T>(Configuration configuration, params T[] workers) where T : IWorkflowTask
{
return new HostBuilder()
.ConfigureServices(
(ctx, services) =>
{
services.AddConductorWorker(configuration);
foreach (var worker in workers)
{
services.AddConductorWorkflowTask(worker);
}
services.WithHostedService();
}
).ConfigureLogging(
logging =>
{
logging.SetMinimumLevel(LogLevel.Debug);
logging.AddConsole();
}
).Build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
using System.Threading;
using System.Collections.Generic;

namespace Tests.Worker
namespace Conductor.Client.Worker
{
public class WorkerService : BackgroundService
public class WorkflowTaskService : BackgroundService
{
private readonly IWorkflowTaskCoordinator _workflowTaskCoordinator;
private readonly IEnumerable<IWorkflowTask> _workers;

public WorkerService(
IWorkflowTaskCoordinator workflowTaskCoordinator,
IEnumerable<IWorkflowTask> workers
)
public WorkflowTaskService(IWorkflowTaskCoordinator workflowTaskCoordinator, IEnumerable<IWorkflowTask> workers)
{
_workflowTaskCoordinator = workflowTaskCoordinator;
_workers = workers;
Expand Down
9 changes: 8 additions & 1 deletion Conductor/Executor/WorkflowExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Conductor.Api;
using Conductor.Definition;
using Conductor.Client;
using Conductor.Client.Models;
using Conductor.Definition;
using System.Collections.Generic;

namespace Conductor.Executor
Expand All @@ -10,6 +11,12 @@ public class WorkflowExecutor
private WorkflowResourceApi _workflowClient;
private MetadataResourceApi _metadataClient;

public WorkflowExecutor(Configuration configuration)
{
_workflowClient = configuration.GetClient<WorkflowResourceApi>();
_metadataClient = configuration.GetClient<MetadataResourceApi>();
}

public WorkflowExecutor(WorkflowResourceApi workflowClient, MetadataResourceApi metadataClient)
{
_workflowClient = workflowClient;
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ using Conductor.Client.Authentication;

var configuration = new Configuration() {
BasePath = basePath,
AuthenticationSettings = new OrkesAuthenticationSettings(keyId, keySecret)
AuthenticationSettings = new OrkesAuthenticationSettings("keyId", "keySecret")
};

var workflowClient = configuration.GetClient<WorkflowResourceApi>();
Expand Down
2 changes: 1 addition & 1 deletion Tests/Util/ApiUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static ApiUtil()
{
_configuration = new Configuration()
{
Timeout = 30000,
Timeout = 7500,
BasePath = GetEnvironmentVariable(ENV_ROOT_URI),
AuthenticationSettings = new OrkesAuthenticationSettings(
GetEnvironmentVariable(ENV_KEY_ID),
Expand Down
29 changes: 12 additions & 17 deletions Tests/Util/WorkerUtil.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
using Conductor.Client.Extensions;
using Microsoft.Extensions.Logging;
using Conductor.Client.Worker;
using Microsoft.Extensions.Hosting;
using Tests.Worker;

namespace Tests.Util
{
public class WorkerUtil
{
private static IHost _host = null;

static WorkerUtil()
{
_host = WorkflowTaskHost.CreateWorkerHost(
ApiUtil.GetConfiguration(),
new SimpleWorker()
);
}

public static IHost GetWorkerHost()
{
return new HostBuilder()
.ConfigureServices(
(ctx, services) =>
{
services.AddConductorWorker(ApiUtil.GetConfiguration());
services.AddConductorWorkflowTask<SimpleWorker>();
services.WithHostedService<WorkerService>();
}
).ConfigureLogging(
logging =>
{
logging.SetMinimumLevel(LogLevel.Debug);
logging.AddConsole();
}
).Build();
return _host;
}
}
}
1 change: 0 additions & 1 deletion docs/readme/executor.md

This file was deleted.

29 changes: 8 additions & 21 deletions docs/readme/workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,16 @@ public class SimpleWorker : IWorkflowTask
```

## Starting Workers
`TaskRunner` interface is used to start the workers, which takes care of polling server for the work, executing worker code and updating the results back to the server.
You can use `WorkflowTaskHost` to create a worker host, it requires a configuration object and then you can add your workers.

```csharp
private IHost GetWorkerHost()
{
return new HostBuilder()
.ConfigureServices(
(ctx, services) =>
{
services.AddConductorWorker(ApiUtil.GetConfiguration());
services.AddConductorWorkflowTask<SimpleWorker>();
services.WithHostedService<WorkerService>();
}
).ConfigureLogging(
logging =>
{
logging.SetMinimumLevel(LogLevel.Debug);
logging.AddConsole();
}
).Build();
}
using Conductor.Client.Worker;
using System;
using System.Threading.Thread;

GetWorkerHost().RunAsync();
var host = WorkflowTaskHost.CreateWorkerHost(configuration, new SimpleWorker());
await host.startAsync();
Thread.Sleep(TimeSpan.FromSeconds(100));
```

Check out our [integration tests](https://github.com/conductor-sdk/conductor-csharp/blob/92c7580156a89322717c94aeaea9e5201fe577eb/Tests/Worker/WorkerTests.cs#L37) for more examples
Expand All @@ -78,4 +65,4 @@ Worker SDK collects the following metrics:

Metrics on client side supplements the one collected from server in identifying the network as well as client side issues.

### Next: [Create and Execute Workflows](/docs/readme/workflow.md)
### Next: [Create and Execute Workflows](https://github.com/conductor-sdk/conductor-csharp/blob/main/docs/readme/workflow.md)
22 changes: 9 additions & 13 deletions docs/readme/workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
## A simple two-step workflow

```csharp
using Conductor.Client;
using Conductor.Definition;
using Conductor.Executor;

ConductorWorkflow GetConductorWorkflow()
{
return new ConductorWorkflow()
Expand All @@ -11,27 +15,19 @@ ConductorWorkflow GetConductorWorkflow()
.WithOwner("[email protected]")
.WithTask(new SimpleTask("simple_task_2", "simple_task_1"))
.WithTask(new SimpleTask("simple_task_1", "simple_task_2"));

WorkflowExecutor GetWorkflowExecutor()
{
return new WorkflowExecutor(
metadataClient: GetClient<MetadataResourceApi>(),
workflowClient: GetClient<WorkflowResourceApi>()
);
}

ConductorWorkflow conductorWorkflow = GetConductorWorkflow();
WorkflowExecutor workflowExecutor = GetWorkflowExecutor();
var configuration = new Configuration();

var conductorWorkflow = GetConductorWorkflow();
var workflowExecutor = new WorkflowExecutor(configuration);
workflowExecutor.RegisterWorkflow(
workflow: conductorWorkflow
overwrite: true
);
String workflowId = workflowExecutor.StartWorkflow(conductorWorkflow);
var workflowId = workflowExecutor.StartWorkflow(conductorWorkflow);
```

### Workflow Management APIs
See [Docs](/docs/readme/executor.md) for APIs to start, pause, resume, terminate, search and get workflow execution status.

### More Examples
You can find more examples at the following GitHub repository:

Expand Down

0 comments on commit b5ec858

Please sign in to comment.