Fix RunTask activity
This fixes the issue where its bookmark would include the activity instance ID, which causes the task completion reporter to miss the bookmark, since the activity instance ID is not included. Including the activity instance ID is not necessary for locating the correct activity instance because the generated Task ID is unique for each activity run. Fixes #4511
This commit is contained in:
parent
c2d9ec4fd2
commit
c9e2b11dfe
|
|
@ -20,10 +20,10 @@ namespace Elsa.Workflows.Runtime.Activities;
|
|||
/// </summary>
|
||||
[Activity("Elsa", "Primitives", "Requests a given task to be run. ", Kind = ActivityKind.Action)]
|
||||
[PublicAPI]
|
||||
public class RunTask : Activity<object>, IBookmarksPersistedHandler
|
||||
public class RunTask : Activity<object>
|
||||
{
|
||||
private static readonly object BookmarkPropertyKey = new();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The key that is used for sending and receiving activity input.
|
||||
/// </summary>
|
||||
|
|
@ -34,19 +34,19 @@ public class RunTask : Activity<object>, IBookmarksPersistedHandler
|
|||
/// </summary>
|
||||
[Input(Description = "The name of the task being requested.")]
|
||||
public Input<string> TaskName { get; set; } = default!;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The name of the task being requested.
|
||||
/// </summary>
|
||||
[Input(Description = "Any additional parameters to send to the task.")]
|
||||
public Input<IDictionary<string, object>?> Payload { get; set; } = default!;
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
[JsonConstructor]
|
||||
private RunTask(string? source = default, int? line = default) : base(source, line)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public RunTask(MemoryBlockReference output, [CallerFilePath] string? source = default, [CallerLineNumber] int? line = default) : base(output, source, line)
|
||||
{
|
||||
|
|
@ -56,20 +56,20 @@ public class RunTask : Activity<object>, IBookmarksPersistedHandler
|
|||
public RunTask(Output<object>? output, [CallerFilePath] string? source = default, [CallerLineNumber] int? line = default) : base(output, source, line)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public RunTask(string taskName, [CallerFilePath] string? source = default, [CallerLineNumber] int? line = default) : this(new Literal<string>(taskName), source, line)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public RunTask(Func<string> taskName, [CallerFilePath] string? source = default, [CallerLineNumber] int? line = default)
|
||||
public RunTask(Func<string> taskName, [CallerFilePath] string? source = default, [CallerLineNumber] int? line = default)
|
||||
: this(new DelegateBlockReference<string>(taskName), source, line)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public RunTask(Func<ExpressionExecutionContext, string?> taskName, [CallerFilePath] string? source = default, [CallerLineNumber] int? line = default)
|
||||
public RunTask(Func<ExpressionExecutionContext, string?> taskName, [CallerFilePath] string? source = default, [CallerLineNumber] int? line = default)
|
||||
: this(new DelegateBlockReference<string?>(taskName), source, line)
|
||||
{
|
||||
}
|
||||
|
|
@ -80,16 +80,23 @@ public class RunTask : Activity<object>, IBookmarksPersistedHandler
|
|||
/// <inheritdoc />
|
||||
public RunTask(Literal<string> taskName, [CallerFilePath] string? source = default, [CallerLineNumber] int? line = default) : base(source, line) => TaskName = new Input<string>(taskName);
|
||||
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Execute(ActivityExecutionContext context)
|
||||
protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
|
||||
{
|
||||
// Create bookmark.
|
||||
var taskName = TaskName.Get(context);
|
||||
var identityGenerator = context.GetRequiredService<IIdentityGenerator>();
|
||||
var taskId = identityGenerator.GenerateId();
|
||||
var payload = new RunTaskBookmarkPayload(taskId, taskName);
|
||||
context.CreateBookmark(payload, ResumeAsync);
|
||||
context.TransientProperties[BookmarkPropertyKey] = payload;
|
||||
context.CreateBookmark(payload, ResumeAsync, includeActivityInstanceId: false);
|
||||
|
||||
// Dispatch task request.
|
||||
var taskParams = Payload.GetOrDefault(context);
|
||||
var runTaskRequest = new RunTaskRequest(context, taskId, taskName, taskParams);
|
||||
var dispatcher = context.GetRequiredService<ITaskDispatcher>();
|
||||
|
||||
await dispatcher.DispatchAsync(runTaskRequest, context.CancellationToken);
|
||||
}
|
||||
|
||||
private async ValueTask ResumeAsync(ActivityExecutionContext context)
|
||||
|
|
@ -98,15 +105,4 @@ public class RunTask : Activity<object>, IBookmarksPersistedHandler
|
|||
context.Set(Result, input);
|
||||
await context.CompleteActivityAsync();
|
||||
}
|
||||
|
||||
async ValueTask IBookmarksPersistedHandler.BookmarksPersistedAsync(ActivityExecutionContext context)
|
||||
{
|
||||
var bookmark = (RunTaskBookmarkPayload)context.TransientProperties[BookmarkPropertyKey];
|
||||
var taskParams = Payload.GetOrDefault(context);
|
||||
var taskName = TaskName.Get(context);
|
||||
var notification = new RunTaskRequest(context, bookmark.TaskId, taskName, taskParams);
|
||||
var dispatcher = context.GetRequiredService<ITaskDispatcher>();
|
||||
|
||||
await dispatcher.DispatchAsync(notification, context.CancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue