Add convenience overload to enqueue workflow by type

This commit is contained in:
Sipke Schoorstra 2021-02-17 21:41:25 +01:00
parent 4d748c8371
commit 3280570252
2 changed files with 18 additions and 5 deletions

View file

@ -2,6 +2,7 @@
using System.Threading;
using System.Threading.Tasks;
using Elsa.Bookmarks;
using Elsa.Builders;
namespace Elsa.Services
{
@ -18,7 +19,7 @@ namespace Elsa.Services
string? correlationId = default,
string? contextId = default,
CancellationToken cancellationToken = default);
/// <summary>
/// Enqueues the specified workflows for execution.
/// </summary>
@ -28,12 +29,17 @@ namespace Elsa.Services
string? correlationId = default,
string? contextId = default,
CancellationToken cancellationToken = default);
/// <summary>
/// Enqueues the specified workflow instance and activity for execution.
/// </summary>
Task EnqueueWorkflowInstance(string workflowInstanceId, string activityId, object? input, CancellationToken cancellationToken = default);
/// <summary>
/// Enqueues the specified workflow definition and activity for execution.
/// </summary>
Task EnqueueWorkflowDefinition<T>(string? tenantId, string activityId, object? input, string? correlationId, string? contextId, CancellationToken cancellationToken) where T : IWorkflow;
/// <summary>
/// Enqueues the specified workflow definition and activity for execution.
/// </summary>

View file

@ -2,6 +2,7 @@
using System.Threading;
using System.Threading.Tasks;
using Elsa.Bookmarks;
using Elsa.Builders;
using Elsa.Messages;
using Open.Linq.AsyncExtensions;
@ -31,7 +32,7 @@ namespace Elsa.Services
await EnqueueWorkflowsAsync(results, input, correlationId, contextId, cancellationToken);
}
public async Task EnqueueWorkflowsAsync(IEnumerable<BookmarkFinderResult> results, object? input = default, string? correlationId = default, string? contextId = default, CancellationToken cancellationToken = default)
public async Task EnqueueWorkflowsAsync(IEnumerable<BookmarkFinderResult> results, object? input, string? correlationId, string? contextId, CancellationToken cancellationToken)
{
foreach (var result in results)
await EnqueueWorkflowInstance(result.WorkflowInstanceId, result.ActivityId, input, cancellationToken);
@ -41,8 +42,14 @@ namespace Elsa.Services
{
await _commandSender.SendAsync(new RunWorkflowInstance(workflowInstanceId, activityId, input));
}
public async Task EnqueueWorkflowDefinition<T>(string? tenantId, string activityId, object? input, string? correlationId, string? contextId, CancellationToken cancellationToken) where T : IWorkflow
{
var workflowDefinitionId = typeof(T).Name;
await EnqueueWorkflowDefinition(workflowDefinitionId, tenantId, activityId, input, correlationId, contextId, cancellationToken);
}
public async Task EnqueueWorkflowDefinition(string workflowDefinitionId, string? tenantId, string activityId, object? input, string? correlationId, string? contextId, CancellationToken cancellationToken = default)
public async Task EnqueueWorkflowDefinition(string workflowDefinitionId, string? tenantId, string activityId, object? input, string? correlationId, string? contextId, CancellationToken cancellationToken)
{
await _commandSender.SendAsync(new RunWorkflowDefinition(workflowDefinitionId, tenantId, activityId, input, correlationId, contextId));
}