Skip to content

Commit

Permalink
Update handling of null outcomes in activity execution
Browse files Browse the repository at this point in the history
The code was adjusted to correctly handle cases when the method `GetBackgroundOutcomes` returns null. This would cause the activity to complete prematurely.

Fixes #4763
  • Loading branch information
sfmskywalker committed Jan 7, 2024
1 parent 900aac6 commit c2ec2bd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public static void SetBackgroundOutcomes(this ActivityExecutionContext activityE
/// <summary>
/// Gets the background outcomes.
/// </summary>
public static IEnumerable<string> GetBackgroundOutcomes(this ActivityExecutionContext activityExecutionContext)
public static IEnumerable<string>? GetBackgroundOutcomes(this ActivityExecutionContext activityExecutionContext)
{
return activityExecutionContext.GetProperty<IEnumerable<string>>("BackgroundOutcomes") ?? Enumerable.Empty<string>();
return activityExecutionContext.GetProperty<IEnumerable<string>>("BackgroundOutcomes");
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public async Task ExecuteAsync(ScheduledBackgroundActivity scheduledBackgroundAc
var outcomesKey = BackgroundActivityInvokerMiddleware.GetBackgroundActivityOutcomesKey(activityNodeId);
var journalDataKey = BackgroundActivityInvokerMiddleware.GetBackgroundActivityJournalDataKey(activityNodeId);
var scheduledActivitiesKey = BackgroundActivityInvokerMiddleware.GetBackgroundActivityScheduledActivitiesKey(activityNodeId);
var outcomes = activityExecutionContext.GetBackgroundOutcomes().ToList();
var outcomes = activityExecutionContext.GetBackgroundOutcomes()?.ToList();
var scheduledActivities = activityExecutionContext.GetBackgroundScheduledActivities().ToList();

var dispatchRequest = new DispatchWorkflowInstanceRequest
Expand All @@ -119,13 +119,15 @@ public async Task ExecuteAsync(ScheduledBackgroundActivity scheduledBackgroundAc
BookmarkId = bookmarkId,
Properties = new Dictionary<string, object>
{
[outcomesKey] = outcomes,
[scheduledActivitiesKey] = JsonSerializer.Serialize(scheduledActivities),
[inputKey] = outputValues,
[journalDataKey] = activityExecutionContext.JournalData
}
};

if (outcomes != null)
dispatchRequest.Properties[outcomesKey] = outcomes;

if (cancellationToken.IsCancellationRequested)
{
_logger.LogInformation("Background execution for activity {ActivityNodeId} was canceled", activityNodeId);
Expand Down

0 comments on commit c2ec2bd

Please sign in to comment.