Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make TriggerEvent retnrun WorkflowExecutionContext #14281

Merged
merged 8 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,17 @@ public Task<ActivityContext> CreateActivityExecutionContextAsync(ActivityRecord
return Task.FromResult(context);
}

public async Task TriggerEventAsync(string name, IDictionary<string, object> input = null, string correlationId = null, bool isExclusive = false, bool isAlwaysCorrelated = false)
public async Task<IEnumerable<WorkflowExecutionContext>> TriggerEventAsync(string name, IDictionary<string, object> input = null, string correlationId = null, bool isExclusive = false, bool isAlwaysCorrelated = false)
{
var activity = _activityLibrary.GetActivityByName(name);
if (activity == null)
{
_logger.LogError("Activity '{ActivityName}' was not found", name);
return;
return Array.Empty<WorkflowExecutionContext>();
}

var triggerdWorkflows = new List<WorkflowExecutionContext>();

// Resume workflow instances halted on this kind of activity for the specified target.
var haltedWorkflows = await _workflowStore.ListByActivityNameAsync(name, correlationId, isAlwaysCorrelated);
foreach (var workflow in haltedWorkflows)
Expand Down Expand Up @@ -193,7 +195,8 @@ public async Task TriggerEventAsync(string name, IDictionary<string, object> inp
var blockingActivities = haltedWorkflow.BlockingActivities.Where(x => x.Name == name).ToArray();
foreach (var blockingActivity in blockingActivities)
{
await ResumeWorkflowAsync(haltedWorkflow, blockingActivity, input);
var context = await ResumeWorkflowAsync(haltedWorkflow, blockingActivity, input);
triggerdWorkflows.Add(context);
}
}

Expand Down Expand Up @@ -242,8 +245,10 @@ public async Task TriggerEventAsync(string name, IDictionary<string, object> inp
}

var startActivity = workflowType.Activities.First(x => x.IsStart && x.Name == name);
await StartWorkflowAsync(workflowType, startActivity, input, correlationId);
var context = await StartWorkflowAsync(workflowType, startActivity, input, correlationId);
triggerdWorkflows.Add(context);
}
return triggerdWorkflows;
}

public async Task<WorkflowExecutionContext> ResumeWorkflowAsync(Workflow workflow, BlockingActivity awaitingActivity, IDictionary<string, object> input = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public interface IWorkflowManager
/// <param name="isAlwaysCorrelated">
/// If true, to be correlated a workflow instance only needs to be halted on an event activity of the related type, regardless the 'correlationId'. False by default.
/// </param>
Task TriggerEventAsync(string name, IDictionary<string, object> input = null, string correlationId = null, bool isExclusive = false, bool isAlwaysCorrelated = false);
Task<IEnumerable<WorkflowExecutionContext>> TriggerEventAsync(string name, IDictionary<string, object> input = null, string correlationId = null, bool isExclusive = false, bool isAlwaysCorrelated = false);
MikeAlhayek marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Starts a new workflow using the specified workflow definition.
Expand Down Expand Up @@ -72,7 +72,7 @@ public interface IWorkflowManager

public static class WorkflowManagerExtensions
{
public static Task TriggerEventAsync(this IWorkflowManager workflowManager, string name, object input = null, string correlationId = null)
public static Task<IEnumerable<WorkflowExecutionContext>> TriggerEventAsync(this IWorkflowManager workflowManager, string name, object input = null, string correlationId = null)
{
return workflowManager.TriggerEventAsync(name, new RouteValueDictionary(input), correlationId);
}
Expand Down
Loading