* Refactor workflow instance deletion to use `IWorkflowRuntime` for enhanced coordination and separation of concerns. * Remove `EnumerableTypeConverter` and update related usages for serialization. - Deleted the `EnumerableTypeConverter` class and its JSON serialization logic. - Removed associated type descriptor attribute in `DefaultFormattersFeature`. - Updated `ObjectFormatter` to handle collection serialization directly with JSON. * Remove `EnumerableTypeConverter` tests and consolidate serialization logic into `ObjectFormatter`. - Deleted `EnumerableTypeConverterTests` as the related functionality was removed. - Added comprehensive tests in `ObjectFormatterTests` to handle serialization of collections and arrays with JSON. * Add integration tests for `TriggerIndexer` to handle workflows with failing materialization - Introduced comprehensive test scenarios verifying `DeleteTriggersAsync` behavior when workflows fail to load or partially succeed. - Enhanced error handling in `TriggerIndexer` to skip failed workflows while ensuring remaining workflows are processed. * Add exception handling in `TriggerIndexer.DeleteTriggersAsync` and integration tests - Enhanced `DeleteTriggersAsync` with exception handling to skip failed workflows while processing others. - Logged warnings for failed workflows without halting execution. - Added comprehensive integration tests to verify behavior across success, failure, and mixed scenarios. - Refactored tests for improved clarity, maintainability, and consistency. * Add exception handling for `ResumeWorkflowTask` to skip deleted workflow instances - Enhanced `ResumeWorkflowTask.ExecuteAsync` to handle `WorkflowInstanceNotFoundException` gracefully when a scheduled workflow instance is missing. - Logged warnings for skipped executions to improve observability. - Ensured remaining workflows and scheduled tasks are processed seamlessly without disruption. * Add thread safety to `LocalScheduler` to prevent race conditions during concurrent scheduling - Introduced a `lock` object to synchronize access to internal dictionaries. - Resolved `IndexOutOfRangeException` caused by concurrent modifications during startup. - Ensured thread-safe operations in `ScheduleAsync`, `ClearScheduleAsync`, and related methods. - Improved reliability and stability of scheduling under concurrent workloads. * Improve exception handling, thread safety, and workflow instance deletion - Added exception handling in `TriggerIndexer.DeleteTriggersAsync` to skip failed workflows while continuing processing. - Enhanced `ResumeWorkflowTask` to handle missing workflow instances gracefully and log warnings. - Introduced thread synchronization in `LocalScheduler` with `lock` to prevent concurrent access issues. - Implemented and refactored tests to ensure behavior consistency and improve maintainability. - Added component tests for workflow deletion scenarios, covering running, completed, and non-existent workflows. * Add component tests for workflow instance deletion and refactor bulk delete logic - Added comprehensive component tests for workflow instance deletion scenarios (running, completed, bulk, and non-existent instances). - Refactored `BulkDelete` API to use `IWorkflowInstanceManager` for proper cleanup of related records (execution logs, activity executions, bookmarks). * Add integration tests and fakes for `TriggerIndexer` to verify behavior with failing and successful workflows - Introduced `FailingMaterializer` and `WorkingMaterializer` for simulating failing and successful workflow materializations. - Added `TriggerDeletionTestScenario`, `TriggerTestDataBuilder`, and related test data classes to define comprehensive test cases. - Updated `DeleteTriggersAsync` tests with scenarios for materialization failures and mixed success. - Improved test coverage and maintainability with reusable test data builders and utilities. * Refactor `ActivityExecutionContextExtensions` to use instance methods for improved readability and encapsulation * Refactor extension methods to use instance methods for improved encapsulation and readability in core workflow modules * Update src/modules/Elsa.Workflows.Core/Pipelines/ActivityExecution/ActivityExecutionMiddlewareExtensions.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/modules/Elsa.Workflows.Core/Pipelines/WorkflowExecution/WorkflowExecutionMiddlewareExtensions.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Refactor `ActivityExecutionContextExtensions` to improve encapsulation and simplify methods - Converted extension methods to instance methods for better readability and maintainability. - Introduced helper methods to encapsulate logic for common operations like detecting unconsumed tokens, running instances, scheduled works, and faulted children. - Improved reusability and cohesion of workflow-related logic. * Change access modifiers in `ActivityExecutionContextExtensions` to improve accessibility and reusability of workflow logic * Update src/modules/Elsa.Workflows.Core/Extensions/ActivityExecutionContextExtensions.InputOutput.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Refactor `ActivityExecutionContextExtensions` for improved readability by simplifying conditional expression --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
42 lines
1.9 KiB
C#
42 lines
1.9 KiB
C#
using Elsa.Workflows;
|
|
|
|
namespace Elsa.Testing.Shared;
|
|
|
|
/// <summary>
|
|
/// Provides extension methods for <see cref="ActivityExecutionContext"/> to enhance its functionality.
|
|
/// </summary>
|
|
public static class ActivityExecutionContextExtensions
|
|
{
|
|
/// <param name="activityExecutionContext">The activity execution context instance used for checking the scheduled activity.</param>
|
|
extension(ActivityExecutionContext activityExecutionContext)
|
|
{
|
|
/// <summary>
|
|
/// Determines whether the specified activity is scheduled in the workflow execution context.
|
|
/// </summary>
|
|
/// <param name="activity">The activity to check for scheduling.</param>
|
|
/// <returns>True if the specified activity is scheduled; otherwise, false.</returns>
|
|
public bool HasScheduledActivity(IActivity activity)
|
|
{
|
|
return activityExecutionContext.WorkflowExecutionContext.Scheduler.Find(x => x.Activity == activity) != null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves the collection of outcomes recorded in the execution context's journal data.
|
|
/// </summary>
|
|
/// <returns>A collection of outcome strings, or an empty collection if no outcomes are present.</returns>
|
|
public IEnumerable<string> GetOutcomes()
|
|
{
|
|
return activityExecutionContext.JournalData.TryGetValue("Outcomes", out var outcomes) && outcomes is string[] arr ? arr : [];
|
|
}
|
|
|
|
/// <summary>
|
|
/// Determines whether the specified outcome exists in the current activity execution context.
|
|
/// </summary>
|
|
/// <param name="outcome">The outcome to verify within the execution context.</param>
|
|
/// <returns>True if the specified outcome exists; otherwise, false.</returns>
|
|
public bool HasOutcome(string outcome)
|
|
{
|
|
return activityExecutionContext.GetOutcomes().Contains(outcome);
|
|
}
|
|
}
|
|
} |