This commit is contained in:
Sipke Schoorstra 2022-09-02 13:36:03 +02:00
parent e2ffafc736
commit 220a1b4593
21 changed files with 3 additions and 367 deletions

View file

@ -66,19 +66,9 @@ public class HttpTriggerMiddleware
);
var input = new Dictionary<string, object>() { [HttpEndpoint.InputKey] = requestModel };
// var stimulus = Stimulus.Standard<HttpEndpoint>(hash, input);
// var executionResults = (await workflowService.ExecuteStimulusAsync(stimulus, abortToken)).ToList();
//
// if (!executionResults.Any())
// {
// await _next(httpContext);
// return;
// }
//await WriteResponseAsync(httpContext, executionResults, abortToken);
}
private static async Task WriteResponseAsync(HttpContext httpContext, IEnumerable<ExecuteWorkflowInstructionResult> executionResults, CancellationToken cancellationToken)
private static async Task WriteResponseAsync(HttpContext httpContext, CancellationToken cancellationToken)
{
var response = httpContext.Response;
@ -89,7 +79,7 @@ public class HttpTriggerMiddleware
var model = new
{
workflowInstanceIds = executionResults.Select(x => x.RunWorkflowResult.WorkflowState.Id).ToArray()
workflowInstanceIds = Array.Empty<string>(),
};
var json = JsonSerializer.Serialize(model);

View file

@ -1,19 +1,10 @@
using System.Collections.Generic;
using Elsa.Workflows.Runtime.Models;
namespace Elsa.Workflows.Api.Endpoints.Events.Trigger;
public class Request
{
public string EventName { get; set; }
public string EventName { get; set; } = default!;
}
public class Response
{
public Response(ICollection<ExecuteWorkflowInstructionResult> items)
{
Items = items;
}
public ICollection<ExecuteWorkflowInstructionResult> Items { get; set; }
}

View file

@ -1,17 +0,0 @@
// using Elsa.Workflows.Runtime.Services;
//
// namespace Elsa.Workflows.Runtime.Abstractions;
//
// public abstract class StimulusHandler<TStimulus> : IStimulusHandler where TStimulus:IStimulus
// {
// bool IStimulusHandler.GetSupportsStimulus(IStimulus stimulus) => stimulus is TStimulus;
// ValueTask<IEnumerable<IWorkflowInstruction>> IStimulusHandler.GetInstructionsAsync(IStimulus stimulus, CancellationToken cancellationToken) => GetInstructionsAsync((TStimulus)stimulus, cancellationToken);
//
// protected virtual ValueTask<IEnumerable<IWorkflowInstruction>> GetInstructionsAsync(TStimulus stimulus, CancellationToken cancellationToken = default)
// {
// var instruction = GetInstructions(stimulus);
// return ValueTask.FromResult(instruction);
// }
//
// protected virtual IEnumerable<IWorkflowInstruction> GetInstructions(TStimulus stimulus) => ArraySegment<IWorkflowInstruction>.Empty;
// }

View file

@ -1,27 +0,0 @@
// using Elsa.Workflows.Runtime.Models;
// using Elsa.Workflows.Runtime.Services;
//
// namespace Elsa.Workflows.Runtime.Abstractions;
//
// public abstract class WorkflowInstructionInterpreter<TInstruction> : IWorkflowInstructionInterpreter where TInstruction: IWorkflowInstruction
// {
// bool IWorkflowInstructionInterpreter.GetSupportsInstruction(IWorkflowInstruction instruction) => instruction is TInstruction;
//
// ValueTask<ExecuteWorkflowInstructionResult?> IWorkflowInstructionInterpreter.ExecuteInstructionAsync(IWorkflowInstruction instruction, CancellationToken cancellationToken) => ExecuteInstructionAsync((TInstruction)instruction, cancellationToken);
// ValueTask<DispatchWorkflowInstructionResult?> IWorkflowInstructionInterpreter.DispatchInstructionAsync(IWorkflowInstruction instruction, CancellationToken cancellationToken) => DispatchInstructionAsync((TInstruction)instruction, cancellationToken);
//
// protected virtual ValueTask<ExecuteWorkflowInstructionResult?> ExecuteInstructionAsync(TInstruction instruction, CancellationToken cancellationToken = default)
// {
// var result = ExecuteInstruction(instruction);
// return ValueTask.FromResult(result);
// }
//
// protected virtual ValueTask<DispatchWorkflowInstructionResult?> DispatchInstructionAsync(TInstruction instruction, CancellationToken cancellationToken = default)
// {
// var result = DispatchInstruction(instruction);
// return ValueTask.FromResult(result);
// }
//
// protected virtual ExecuteWorkflowInstructionResult? ExecuteInstruction(TInstruction instruction) => null;
// protected virtual DispatchWorkflowInstructionResult? DispatchInstruction(TInstruction instruction) => null;
// }

View file

@ -14,6 +14,4 @@ public static class DependencyInjectionExtensions
}
public static IServiceCollection AddWorkflowDefinitionProvider<T>(this IServiceCollection services) where T : class, IWorkflowDefinitionProvider => services.AddSingleton<IWorkflowDefinitionProvider, T>();
// public static IServiceCollection AddStimulusHandler<T>(this IServiceCollection services) where T : class, IStimulusHandler => services.AddSingleton<IStimulusHandler, T>();
// public static IServiceCollection AddInstructionInterpreter<T>(this IServiceCollection services) where T : class, IWorkflowInstructionInterpreter => services.AddSingleton<IWorkflowInstructionInterpreter, T>();
}

View file

@ -1,20 +0,0 @@
// using Elsa.Workflows.Runtime.Services;
//
// namespace Elsa.Workflows.Runtime.Implementations;
//
// public class StimulusInterpreter : IStimulusInterpreter
// {
// private readonly IEnumerable<IStimulusHandler> _workflowExecutionInstructionProviders;
//
// public StimulusInterpreter(IEnumerable<IStimulusHandler> workflowExecutionInstructionProviders)
// {
// _workflowExecutionInstructionProviders = workflowExecutionInstructionProviders;
// }
//
// public async Task<IEnumerable<IWorkflowInstruction>> GetExecutionInstructionsAsync(IStimulus stimulus, CancellationToken cancellationToken = default)
// {
// var providers = _workflowExecutionInstructionProviders.Where(x => x.GetSupportsStimulus(stimulus)).ToList();
// var tasks = providers.Select(x => x.GetInstructionsAsync(stimulus, cancellationToken).AsTask());
// return (await Task.WhenAll(tasks)).SelectMany(x => x);
// }
// }

View file

@ -1,42 +0,0 @@
// using Elsa.Workflows.Runtime.Models;
// using Elsa.Workflows.Runtime.Services;
//
// namespace Elsa.Workflows.Runtime.Implementations;
//
// public class WorkflowInstructionExecutor : IWorkflowInstructionExecutor
// {
// private readonly IEnumerable<IWorkflowInstructionInterpreter> _workflowExecutionInstructionHandlers;
//
// public WorkflowInstructionExecutor(IEnumerable<IWorkflowInstructionInterpreter> workflowExecutionInstructionHandlers)
// {
// _workflowExecutionInstructionHandlers = workflowExecutionInstructionHandlers;
// }
//
// public async Task<IEnumerable<ExecuteWorkflowInstructionResult>> ExecuteInstructionAsync(IWorkflowInstruction instruction, CancellationToken cancellationToken = default)
// {
// var handlers = _workflowExecutionInstructionHandlers.Where(x => x.GetSupportsInstruction(instruction)).ToList();
// var tasks = handlers.Select(x => x.ExecuteInstructionAsync(instruction, cancellationToken).AsTask());
// var results = await Task.WhenAll(tasks);
// return results.Where(x => x != null).Select(x => x!).ToList();
// }
//
// public async Task<IEnumerable<ExecuteWorkflowInstructionResult>> ExecuteInstructionsAsync(IEnumerable<IWorkflowInstruction> instructions, CancellationToken cancellationToken = default)
// {
// var tasks = instructions.Select(x => ExecuteInstructionAsync(x, cancellationToken));
// return (await Task.WhenAll(tasks)).SelectMany(x => x);
// }
//
// public async Task<IEnumerable<DispatchWorkflowInstructionResult>> DispatchInstructionAsync(IWorkflowInstruction instruction, CancellationToken cancellationToken = default)
// {
// var handlers = _workflowExecutionInstructionHandlers.Where(x => x.GetSupportsInstruction(instruction)).ToList();
// var tasks = handlers.Select(x => x.DispatchInstructionAsync(instruction, cancellationToken).AsTask());
// var results = await Task.WhenAll(tasks);
// return results.Where(x => x != null).Select(x => x!).ToList();
// }
//
// public async Task<IEnumerable<DispatchWorkflowInstructionResult>> DispatchInstructionsAsync(IEnumerable<IWorkflowInstruction> instructions, CancellationToken cancellationToken = default)
// {
// var tasks = instructions.Select(x => DispatchInstructionAsync(x, cancellationToken));
// return (await Task.WhenAll(tasks)).SelectMany(x => x);
// }
// }

View file

@ -1,88 +0,0 @@
// using Elsa.Models;
// using Elsa.Workflows.Core.Models;
// using Elsa.Workflows.Core.Services;
// using Elsa.Workflows.Persistence.Entities;
// using Elsa.Workflows.Runtime.Models;
// using Elsa.Workflows.Runtime.Services;
//
// namespace Elsa.Workflows.Runtime.Implementations;
//
// public class WorkflowService : IWorkflowService
// {
// private readonly IWorkflowInvoker _workflowInvoker;
// private readonly IWorkflowDispatcher _workflowDispatcher;
// private readonly IHasher _hasher;
//
// public WorkflowService(
// IWorkflowInvoker workflowInvoker,
// IWorkflowDispatcher workflowDispatcher,
// IHasher hasher)
// {
// _workflowInvoker = workflowInvoker;
// _workflowDispatcher = workflowDispatcher;
// _hasher = hasher;
// }
//
// public async Task<ExecuteWorkflowResult> ExecuteWorkflowAsync(string definitionId, VersionOptions versionOptions, IDictionary<string, object>? input = default, string? correlationId = default, CancellationToken cancellationToken = default)
// {
// var executeRequest = new InvokeWorkflowDefinitionRequest(definitionId, versionOptions, input, correlationId);
// var result = await _workflowInvoker.InvokeAsync(executeRequest, cancellationToken);
//
// return new ExecuteWorkflowResult(result.WorkflowState, result.Bookmarks);
// }
//
// public async Task<ExecuteWorkflowResult> ExecuteWorkflowAsync(string instanceId, Bookmark bookmark, IDictionary<string, object>? input = default, string? correlationId = default, CancellationToken cancellationToken = default)
// {
// var request = new InvokeWorkflowInstanceRequest(instanceId, bookmark, input, correlationId);
// var result = await _workflowInvoker.InvokeAsync(request, cancellationToken);
// return new ExecuteWorkflowResult(result.WorkflowState, result.Bookmarks);
// }
//
// public async Task<DispatchWorkflowDefinitionResponse> DispatchWorkflowAsync(string definitionId, VersionOptions versionOptions, IDictionary<string, object>? input = default, string? correlationId = default, CancellationToken cancellationToken = default)
// {
// var executeRequest = new DispatchWorkflowDefinitionRequest(definitionId, versionOptions, input, correlationId);
// return await _workflowDispatcher.DispatchAsync(executeRequest, cancellationToken);
// }
//
// public async Task<DispatchWorkflowInstanceResponse> DispatchWorkflowAsync(string instanceId, Bookmark bookmark, IDictionary<string, object>? input = default, string? correlationId = default, CancellationToken cancellationToken = default)
// {
// var request = new DispatchWorkflowInstanceRequest(instanceId, bookmark, input, correlationId);
// return await _workflowDispatcher.DispatchAsync(request, cancellationToken);
// }
//
// protected override async ValueTask<ExecuteWorkflowInstructionResult?> ResumeWorkflowAsync(WorkflowBookmark workflowBookmark, CancellationToken cancellationToken = default)
// {
// // var workflowDefinitionId = workflowBookmark.WorkflowDefinitionId;
// // var workflowInstanceId = workflowBookmark.WorkflowInstanceId;
// // var workflowInstance = await _workflowInstanceStore.FindByIdAsync(workflowInstanceId, cancellationToken);
// //
// // if (workflowInstance == null)
// // {
// // _logger
// // .LogWarning(
// // "Workflow bookmark {WorkflowBookmarkId} for workflow definition {WorkflowDefinitionId} references workflow instance ID {WorkflowInstanceId}, but no such workflow instance was found", workflowBookmark.Id, workflowBookmark.WorkflowDefinitionId, workflowBookmark.WorkflowInstanceId);
// //
// // return null;
// // }
// //
// // var definition = (await _workflowDefinitionStore.FindManyByDefinitionIdAsync(workflowDefinitionId, VersionOptions.SpecificVersion(workflowInstance.Version), cancellationToken)).FirstOrDefault();
// //
// // if (definition == null)
// // {
// // _logger.LogWarning("Workflow bookmark {WorkflowBookmarkId} references workflow definition ID {WorkflowDefinitionId}, but no such workflow definition was found", workflowBookmark.Id, workflowBookmark.WorkflowDefinitionId);
// // return null;
// // }
// //
// // // Resume workflow instance.
// // var bookmark = new Bookmark(workflowBookmark.Id, workflowBookmark.Name, workflowBookmark.Hash, workflowBookmark.Data, workflowBookmark.ActivityId, workflowBookmark.ActivityInstanceId, workflowBookmark.CallbackMethodName);
// // var workflowState = workflowInstance.WorkflowState;
// // var input = instruction.Input;
// // var workflow = await _workflowDefinitionService.MaterializeWorkflowAsync(definition, cancellationToken);
// // var workflowExecutionResult = await _workflowInvoker.InvokeAsync(workflow, workflowState, bookmark, input, cancellationToken);
// //
// // // Update workflow instance with new workflow state.
// // workflowInstance.WorkflowState = workflowExecutionResult.WorkflowState;
// //
// // return new ExecuteWorkflowInstructionResult(workflowExecutionResult);
// }
// }

View file

@ -1,3 +0,0 @@
namespace Elsa.Workflows.Runtime.Models;
public record DispatchWorkflowInstructionResult();

View file

@ -1,22 +0,0 @@
// using Elsa.Workflows.Core;
// using Elsa.Workflows.Core.Helpers;
// using Elsa.Workflows.Core.Services;
// using Elsa.Workflows.Runtime.Stimuli;
//
// namespace Elsa.Workflows.Runtime.Models;
//
// public static class Stimulus
// {
// public static StandardStimulus Standard<T>(string? hash = default, IDictionary<string, object>? input = default, string? correlationId = default) where T : IActivity =>
// new(ActivityTypeNameHelper.GenerateTypeName<T>(), hash, input, correlationId);
//
// public static StandardStimulus Standard<T>(string? hash, object input, string? correlationId = default) where T : IActivity =>
// new(ActivityTypeNameHelper.GenerateTypeName<T>(), hash, input.ToDictionary(), correlationId);
//
// public static StandardStimulus Standard<T>(object input, string? correlationId = default) where T : IActivity =>
// new(ActivityTypeNameHelper.GenerateTypeName<T>(), default, input.ToDictionary(), correlationId);
//
// public static StandardStimulus Standard(string activityTypeName, string? hash = default, IDictionary<string, object>? input = default, string? correlationId = default) => new(activityTypeName, hash, input, correlationId);
// public static StandardStimulus Standard(string activityTypeName, string? hash, object? input, string? correlationId = default) => new(activityTypeName, hash, input?.ToDictionary(), correlationId);
// public static StandardStimulus Standard(string activityTypeName, object? input, string? correlationId = default) => new(activityTypeName, default, input?.ToDictionary(), correlationId);
// }

View file

@ -1,5 +0,0 @@
// namespace Elsa.Workflows.Runtime.Services;
//
// public interface IStimulus
// {
// }

View file

@ -1,7 +0,0 @@
// namespace Elsa.Workflows.Runtime.Services;
//
// public interface IStimulusHandler
// {
// bool GetSupportsStimulus(IStimulus stimulus);
// ValueTask<IEnumerable<IWorkflowInstruction>> GetInstructionsAsync(IStimulus stimulus, CancellationToken cancellationToken = default);
// }

View file

@ -1,6 +0,0 @@
// namespace Elsa.Workflows.Runtime.Services;
//
// public interface IStimulusInterpreter
// {
// Task<IEnumerable<IWorkflowInstruction>> GetExecutionInstructionsAsync(IStimulus stimulus, CancellationToken cancellationToken = default);
// }

View file

@ -1,5 +0,0 @@
namespace Elsa.Workflows.Runtime.Services;
public interface IWorkflowInstruction
{
}

View file

@ -1,11 +0,0 @@
// using Elsa.Workflows.Runtime.Models;
//
// namespace Elsa.Workflows.Runtime.Services;
//
// public interface IWorkflowInstructionExecutor
// {
// Task<IEnumerable<ExecuteWorkflowInstructionResult>> ExecuteInstructionAsync(IWorkflowInstruction instruction, CancellationToken cancellationToken = default);
// Task<IEnumerable<ExecuteWorkflowInstructionResult>> ExecuteInstructionsAsync(IEnumerable<IWorkflowInstruction> instructions, CancellationToken cancellationToken = default);
// Task<IEnumerable<DispatchWorkflowInstructionResult>> DispatchInstructionAsync(IWorkflowInstruction instruction, CancellationToken cancellationToken = default);
// Task<IEnumerable<DispatchWorkflowInstructionResult>> DispatchInstructionsAsync(IEnumerable<IWorkflowInstruction> instructions, CancellationToken cancellationToken = default);
// }

View file

@ -1,10 +0,0 @@
using Elsa.Workflows.Runtime.Models;
namespace Elsa.Workflows.Runtime.Services;
public interface IWorkflowInstructionInterpreter
{
bool GetSupportsInstruction(IWorkflowInstruction instruction);
ValueTask<ExecuteWorkflowInstructionResult?> ExecuteInstructionAsync(IWorkflowInstruction instruction, CancellationToken cancellationToken = default);
ValueTask<DispatchWorkflowInstructionResult?> DispatchInstructionAsync(IWorkflowInstruction instruction, CancellationToken cancellationToken = default);
}

View file

@ -1,9 +0,0 @@
using Elsa.Workflows.Runtime.Models;
namespace Elsa.Workflows.Runtime.Services;
public interface IWorkflowInstructionScheduler
{
Task<IEnumerable<ExecuteWorkflowInstructionResult?>> ScheduleInstructionAsync(IWorkflowInstruction instruction, CancellationToken cancellationToken = default);
Task<IEnumerable<ExecuteWorkflowInstructionResult?>> ScheduleInstructionsAsync(IEnumerable<IWorkflowInstruction> instructions, CancellationToken cancellationToken = default);
}

View file

@ -1,22 +0,0 @@
// using Elsa.Models;
// using Elsa.Workflows.Core.Models;
// using Elsa.Workflows.Runtime.Models;
//
// namespace Elsa.Workflows.Runtime.Services;
//
// /// <summary>
// /// Represents a high-level service to invoke workflows.
// /// </summary>
// public interface IWorkflowService
// {
// Task<ExecuteWorkflowResult> ExecuteWorkflowAsync(string definitionId, VersionOptions versionOptions, IDictionary<string, object>? input = default, string? correlationId = default, CancellationToken cancellationToken = default);
// Task<ExecuteWorkflowResult> ExecuteWorkflowAsync(string instanceId, Bookmark bookmark, IDictionary<string, object>? input = default, string? correlationId = default, CancellationToken cancellationToken = default);
// Task<DispatchWorkflowDefinitionResponse> DispatchWorkflowAsync(string definitionId, VersionOptions versionOptions, IDictionary<string, object>? input = default, string? correlationId = default, CancellationToken cancellationToken = default);
// Task<DispatchWorkflowInstanceResponse> DispatchWorkflowAsync(string instanceId, Bookmark bookmark, IDictionary<string, object>? input = default, string? correlationId = default, CancellationToken cancellationToken = default);
// // Task<IEnumerable<ExecuteWorkflowInstructionResult>> ExecuteStimulusAsync(IStimulus stimulus, CancellationToken cancellationToken = default);
// // Task<IEnumerable<DispatchWorkflowInstructionResult>> DispatchStimulusAsync(IStimulus stimulus, CancellationToken cancellationToken = default);
// // Task<IEnumerable<DispatchWorkflowInstructionResult>> DispatchStimulusAsync(string bookmarkName, object bookmarkPayload, object inputs, string? correlationId = default, CancellationToken cancellationToken = default);
// // Task<IEnumerable<DispatchWorkflowInstructionResult>> DispatchStimulusAsync(string bookmarkName, object bookmarkPayload, IDictionary<string, object> inputs, string? correlationId = default, CancellationToken cancellationToken = default);
// // Task<IEnumerable<DispatchWorkflowInstructionResult>> DispatchStimulusAsync(string bookmarkName, object bookmarkPayload, string? correlationId = default, CancellationToken cancellationToken = default);
//
// }

View file

@ -1,19 +0,0 @@
// using Elsa.Workflows.Persistence.Services;
// using Elsa.Workflows.Runtime.Abstractions;
// using Elsa.Workflows.Runtime.Interpreters;
// using Elsa.Workflows.Runtime.Services;
// using Open.Linq.AsyncExtensions;
//
// namespace Elsa.Workflows.Runtime.Stimuli.Handlers;
//
// public class ResumeWorkflowsStimulusHandler : StimulusHandler<StandardStimulus>
// {
// private readonly IWorkflowBookmarkStore _bookmarkStore;
// public ResumeWorkflowsStimulusHandler(IWorkflowBookmarkStore bookmarkStore) => _bookmarkStore = bookmarkStore;
//
// protected override async ValueTask<IEnumerable<IWorkflowInstruction>> GetInstructionsAsync(StandardStimulus stimulus, CancellationToken cancellationToken = default)
// {
// var workflowBookmarks = await _bookmarkStore.FindManyAsync(stimulus.ActivityTypeName, stimulus.Hash, cancellationToken).ToList();
// return workflowBookmarks.Select(x => new ResumeWorkflowInstruction(x, stimulus.Input, stimulus.CorrelationId));
// }
// }

View file

@ -1,22 +0,0 @@
// using Elsa.Workflows.Persistence.Services;
// using Elsa.Workflows.Runtime.Abstractions;
// using Elsa.Workflows.Runtime.Interpreters;
// using Elsa.Workflows.Runtime.Services;
//
// namespace Elsa.Workflows.Runtime.Stimuli.Handlers;
//
// public class TriggerWorkflowsStimulusHandler : StimulusHandler<StandardStimulus>
// {
// private readonly IWorkflowTriggerStore _workflowTriggerStore;
//
// public TriggerWorkflowsStimulusHandler(IWorkflowTriggerStore workflowTriggerStore)
// {
// _workflowTriggerStore = workflowTriggerStore;
// }
//
// protected override async ValueTask<IEnumerable<IWorkflowInstruction>> GetInstructionsAsync(StandardStimulus stimulus, CancellationToken cancellationToken = default)
// {
// var workflowTriggers = (await _workflowTriggerStore.FindManyByNameAsync(stimulus.ActivityTypeName, stimulus.Hash, cancellationToken)).ToList();
// return workflowTriggers.Select(x => new TriggerWorkflowInstruction(x, stimulus.Input, stimulus.CorrelationId));
// }
// }

View file

@ -1,8 +0,0 @@
// using Elsa.Workflows.Runtime.Services;
//
// namespace Elsa.Workflows.Runtime.Stimuli;
//
// /// <summary>
// /// Represents a simple stimulus that targets a specific activity type and optionally a corresponding hash to use as a bookmark lookup.
// /// </summary>
// public record StandardStimulus(string ActivityTypeName, string? Hash = default, IDictionary<string, object>? Input = default, string? CorrelationId = default) : IStimulus;