Commit graph

648 commits

Author SHA1 Message Date
Sipke Schoorstra f4a31079b7 Refactor activity execution context removal logic.
Updated methods to ensure proper cleanup when removing activity execution contexts, including handling parent-child relationships. Improved robustness and clarity by introducing step-by-step removal for multiple contexts.
2025-01-29 16:18:59 +01:00
Sipke Schoorstra 0eec9693f7 Refactor and optimize workflow execution context handling.
Replaced inline filtering logic with reusable methods to simplify and unify activity execution context management. Introduced `ClearCompletedActivityExecutionContexts` to remove redundant contexts and migrated filtering logic to `WorkflowExecutionContext`. Improved code clarity and maintainability by removing duplicate methods and streamlining exception throwing.
2025-01-28 20:59:27 +01:00
Sipke Schoorstra 8bc6fa6a57 Refactor activity context management and state handling.
Replaced `ActivityExecutionRecordExtractor` with a `ChangeTrackingDictionary` for better state mutation tracking in activity execution contexts. Introduced tainting mechanisms to track dirty states and ensure precise logging and persistence of activity execution logs. Updated several components like `ActivityExecutionLogSink` and `ExpressionExecutionContext` to utilize these changes effectively.
2025-01-28 20:24:53 +01:00
Sipke Schoorstra dbd89905c8 Remove redundant PreviousSubStatus assignment in workflow context
The PreviousSubStatus assignment was removed as it was unused and unnecessary. This cleanup simplifies the code and ensures focus only on relevant functionality.
2025-01-28 11:40:14 +01:00
Sipke Schoorstra 633464eb04
Merge branch 'main' into feature/4835 2025-01-28 11:17:14 +01:00
Sipke Schoorstra 9a5181a3d7
WIP on feature/4835 2025-01-28 11:17:02 +01:00
Sipke Schoorstra 85282f9149
Update WorkflowExecutionContext.cs
Remove unused property
2025-01-27 21:48:14 +01:00
Sipke Schoorstra 6b288e1990
Update SetCommitStateBehavior method for fluent convenience 2025-01-27 21:13:49 +01:00
Sipke Schoorstra 8cb43db070 Refactor workflow state persistence for improved consistency.
Removed obsolete middleware for persisting bookmarks, execution logs, and variables, integrating their functionality into the commit state handler. Added early exit checks for empty collections in persistence methods. Updated activity invoker logic for better state commit handling during execution.
2025-01-27 20:07:23 +01:00
Sipke Schoorstra 879e546942
Merge branch 'main' into feature/4835 2025-01-27 19:29:43 +01:00
Sipke Schoorstra 7a21f09ae9 Restore methods for traversing activity execution context hierarchy
Reintroduced `GetAncestors` method and added new methods: `GetDescendants`, `GetActiveChildren`, and `GetChildren`. These methods enhance navigation through activity execution contexts by providing easy access to hierarchical relationships like ancestors, descendants, and children.
2025-01-27 15:49:25 +01:00
Sipke Schoorstra 9365328f0b Add commit state behavior support in workflows
Introduced `ActivityCommitStateBehavior` and `WorkflowCommitStateOptions` to enable flexible state commit handling in workflows. Integrated commit logic into activity and workflow execution contexts and middleware. This improves control over when state is committed during workflow execution.
2025-01-25 23:26:37 +01:00
Sipke Schoorstra 0bb183f1aa Fix spacing inconsistencies in ActivityOutputRegister.cs
Resolved unnecessary whitespace issues and adjusted spacing around conditional statements to improve code readability and maintain consistency. These changes do not alter functionality but enhance the code's clarity and professional formatting.
2025-01-21 22:57:19 +01:00
Sipke Schoorstra 1ca8f2a423 Fix null reference issue in ActivityOutputRegister.
Updated the method to safely access the `Value` property when retrieving the first record, preventing potential null reference exceptions. This ensures more robust and error-free behavior when querying output records.
2025-01-21 22:53:08 +01:00
Sipke Schoorstra dd39ca8d84 Refactor variable handling and activity output registration.
Replaced default value assignments with null for clarity and simplicity. Refactored ActivityOutputRegister to optimize record storage and retrieval using grouped dictionary entries instead of flat lists. Adjusted related methods to improve performance and maintain consistency.
2025-01-21 20:10:54 +01:00
Sipke Schoorstra 33a2fb7afe Optimize ActivityOutputRegister.
Enhanced `ActivityOutputRegister` with dictionary-based lookups for improved performance and added unique key generation methods to efficiently retrieve outputs.
2025-01-21 19:52:30 +01:00
Sipke Schoorstra a7360ed922 Add option to disable variable copying in Jint engine
Introduce a `DisableVariableCopying` option to improve performance by preventing workflow variables from being copied into the Jint engine or back into the workflow context. Updated related logic to honor this setting and ensure compatibility with existing behavior.
2025-01-21 19:11:31 +01:00
Sipke Schoorstra d31661926d Simplify activity context handling in workflows.
Replaced `GetActiveChildren` with a direct `Children` property in `Flowchart.cs` to streamline logic. Removed redundant `GetDescendents`, `GetActiveChildren`, and `GetChildren` methods from `ActivityExecutionContextExtensions.cs`. Also updated GitHub workflows to allow performance-related branches.
2025-01-20 18:29:13 +01:00
Sipke Schoorstra a49bf0c05f Refactor descendant context check in Flowchart activity.
Replaced usage of `GetDescendents` with `Children` property for better clarity and efficiency when checking running activity instances. This simplifies the logic and aligns with the existing structure of activity context handling.
2025-01-20 18:07:14 +01:00
Sipke Schoorstra 7e058ddf15 Refactor workflow context and execution handling.
Optimized activity execution context management by introducing parent-child relationships and improving immutability. Adjusted several APIs to enhance clarity, performance, and maintainability, including the use of `AsReadOnly` collections and removal of redundant code.
2025-01-20 17:44:31 +01:00
Sipke Schoorstra a980022351 Refactor exception handling and activity status logic
Refactored `ExceptionHandlingMiddleware` to improve readability and modularity by splitting responsibilities into smaller methods. Replaced `GetAggregateStatus` with direct use of `source.Status` for significant performance improvement when a large number of activity instances are involved. Updated null-checks for clarity and fixed inconsistent usage of default values.
2025-01-20 13:58:11 +01:00
Sipke Schoorstra 1ee8fbdb5a Refactor default parameter values to null for readability
Replaced `default` with `null` for optional parameters to improve code clarity and maintain consistency. This change ensures better readability and aligns with common coding practices, especially when null is the intended default value.
2025-01-15 14:27:53 +01:00
Sipke Schoorstra 2c3843d5f5 Refactor variable mapping and improve type alias handling
Updated `VariableMapper` for null assignment consistency and streamlined `VariableModel` instantiation. Improved `TypeJsonConverter` to handle list type aliases more explicitly, replacing ambiguous syntax with clearer format.
2025-01-15 10:50:34 +01:00
Marius Vasile Vușcan 190d6c3bda
Improvements 2025-01-14 14:43:58 +02:00
Marius Vasile Vușcan e365d44637
Added DeleteVariablesAsync method for the workflow context 2025-01-14 14:41:49 +02:00
Sipke Schoorstra b2331f73db Handle collection and array serialization in TypeJsonConverter
Refactored TypeJsonConverter to distinguish and properly handle serialization of arrays and generic collections. Updated integration tests to include cases for round-tripping primitive arrays and collections for improved coverage.
2025-01-11 20:23:05 +01:00
Sipke Schoorstra 48c453d153 Enable customizable Hangfire job storage and deprecate obsolete APIs.
Added support for configuring Hangfire job storage per database provider, including PostgreSql, SQLite, and SQL Server. Introduced new methods for flexible Hangfire setup, while marking older APIs and storage configuration extensions as obsolete. Refactored related configurations for streamlined and centralized job scheduling logic.
2025-01-11 19:12:38 +01:00
Sipke Schoorstra d759624321 Refactor array type handling in variable and JSON converters
Updated the logic to use `MakeArrayType` for array handling instead of generic collection types, ensuring consistency and better alignment with expected type structures. Adjustments were made in both the `VariableDefinitionMapper` and the `TypeJsonConverter`.
2025-01-10 11:40:54 +01:00
Sipke Schoorstra 67b950f86c Refactor to use target-typed object creation
Replaced explicit type initializations with concise target-typed `new()` expressions where applicable, improving code readability and aligning with updated C# conventions. Updated .editorconfig to enforce consistent use of `var` for type declarations.
2025-01-09 10:27:55 +01:00
Sipke Schoorstra aef5921979 Refactor reference handling in serialization classes
Replaces static resolver state with an instance-level resolver in `CrossScopedReferenceHandler` to enhance flexibility and thread-safety. Refactors `JsonWorkflowStateSerializer` to use `GetOptions` for improved API consistency and clarity.
2025-01-06 18:11:11 +01:00
Sipke Schoorstra 25d9608b25 Refactor reference handling logic for serialization.
Replaced `PerCallReferenceHandlerWrapper` with `CrossScopedReferenceHandler` and optimized the resolver initialization using `AsyncLocal`. This simplifies the code and ensures a more efficient handling of reference resolution during serialization.
2025-01-06 17:57:05 +01:00
Sipke Schoorstra a3ce523faa Fix missing base method call in ApplyOptions implementation
The `ApplyOptions` method now correctly calls the base implementation before applying custom configurations. This ensures that any base behavior is preserved, preventing potential issues with serialization options.
2025-01-06 17:27:24 +01:00
Sipke Schoorstra d2777f70de Refactor reference handling to use a wrapper class
Replaced direct use of `CrossScopedReferenceHandler` with `PerCallReferenceHandlerWrapper` for improved abstraction and reusability. Updated `ApplyOptions` to leverage the new wrapper, simplifying reference resolver management. Commented out redundant code to streamline the implementation.
2025-01-06 17:13:20 +01:00
Sipke Schoorstra ba4645ea62 Refactor JsonWorkflowStateSerializer to improve performance
- **Improves performance:** The converters and static properties are pre-configured when the class is initialized. Only the `ReferenceHandler` is refreshed per call, avoiding repeated configuration of common options like converters.
- **Thread-safe:** Since `_cachedOptions` is immutable, it can safely be reused across threads.

**Tradeoffs:** Small performance cost during cloning, but still much faster than fully recreating options each time.
2025-01-06 15:34:43 +01:00
Sipke Schoorstra fdd71f8007 Handle exceptions in variable loading and fix type checking.
Added try-catch block to log failures when reading variables from storage, ensuring robust error handling. Also refined type checking for `ExpandoObject` deserialization in `ObjectConverter` to prevent invalid operations.
2025-01-01 22:07:49 +01:00
Mathijs Dumon c25ef53dcc Fix for #6082 - dropdowns are not populated for inputs without UIHints 2024-12-16 16:15:58 +01:00
Sipke Schoorstra a1652f3f23 Refactor activity cancellation and bookmark handling.
Added logic to cancel child activities during activity cancellation. Removed redundant bookmark removal logic in the `Fork` activity for better clarity and efficiency.
2024-12-14 21:02:14 +01:00
Sipke Schoorstra b9bde79638 Refactor variable handling in storage driver logic
Refactored `StorageDriverContext` to include `Variable` and updated its usage across relevant methods to ensure context accuracy. Enhanced `ObjectConverter` to support conditional deserialization of JSON objects. Adjusted `WorkflowInstanceStorageDriver` to utilize improved variable resolution with new conversion options.
2024-12-13 12:09:04 +01:00
Sipke Schoorstra 2cd90ad011 Fix logging to display full variable type on parse failure
Updated the log message to use the full variable type name instead of the base type. This provides more detailed context for debugging failed variable parsing issues.
2024-12-12 23:08:48 +01:00
Sipke Schoorstra 9aed23278e Improve error message for invalid variable type cast
Updated the exception message to use the full type name of the variable, providing clearer details for debugging type compatibility issues during variable value parsing.
2024-12-12 23:06:50 +01:00
Sipke Schoorstra b1f839a517 Improve variable parsing with error handling and logging
Added `TryParseValue` method to handle parse errors gracefully and prevent crashes. Updated `VariablePersistenceManager` to log warnings when variable parsing fails, providing better debugging support and resilience during workflow execution.
2024-12-12 23:03:20 +01:00
Marius Vasile Vușcan 687c9d616e
Fixed variable value retrieval 2024-12-12 12:18:32 +02:00
Sipke Schoorstra fa9f83f11f Disable activity state filtering temporarily.
Commented out state filtering logic to address issues with log sanitization. The raw value is now directly stored in the activity state until a redesigned solution is implemented.
2024-12-11 18:11:36 +01:00
Sipke Schoorstra 2af951f6c3 Update display name in WorkflowStorageDriver
Remove the "Deprecated" label from the display name for clarity while keeping the `Obsolete` attribute to indicate planned deprecation. This ensures better alignment between the display name and actual usage guidance.
2024-12-11 16:01:57 +01:00
Marius Vasile Vușcan 95e3b15106
Updated to allow string tags 2024-12-11 16:45:23 +02:00
Marius Vasile Vușcan 16122182e2
Introduce the possibility to exclude variable value retrieval for certain storage drivers 2024-12-11 16:45:18 +02:00
Robin Sue 3bc1cc3ae6 Undo putting _type first for now 2024-12-04 15:47:02 +01:00
Robin Sue c4a6ce2796 Fix Primitive Collection serialization
This was broken by both #5871 and #5682:
1. When a List<Guid> was serialized, it was recognized as a primitive collection and thus plainly written to the JSON without any type information: ["d4d8404c-4357-47ff-a343-649a116539f5"]
2. When this JSON was deserialized, due to lack of type info, it was deserialized as List<object>, containing strings. This is already not good.
3. When this List<object> gets serialized again (e.g. due to multiple workflow suspends causing WorkflowState serialization), this time it fails the primitive collection recognition, because object is not a primitive type. It now gets serialized as {"_items": ["d4d8404c-4357-47ff-a343-649a116539f5"], "_type": "Object[]"}
4. When that JSON gets deserialized, it tries to ReadType() but ReadType() fails to parse Object[] since it lacks the logic from TypeJsonConverter to throw away the [] before looking up Object in the WellKnownTypeRegistry, so it returns null as a type. Without a type but being faced with a json object { ... } it now deserializes into an ExpandoObject
5. Any further serialization / deserializations will now cause the expando object to get nested deeper and deeper every time.
2024-12-04 15:47:01 +01:00
Sipke Schoorstra 97b59974d9
Refactor and reorganize Workflow Storage modules. (#6177)
Moved WorkflowStorageDriver and WorkflowInstanceStorageDriver to a new namespace, VariableStorageDrivers, to improve organization. Updated namespaces in related services and ensured backward compatibility with comments. Minor fix made to TypeJsonConverter for consistency and additional configuration adjustments to support the new structure.
2024-12-04 15:32:40 +01:00
Sipke Schoorstra 08632471e3
Implement Dynamic Expression Evaluation for Log Persistence Mode (#6159)
* Add log persistence configuration and strategy evaluation

Introduced `LogPersistenceConfiguration` to support dynamic strategy and expression-based log persistence evaluations. Updated `Default default values.

* Add LogPersistenceConfiguration and enum support

Introduced LogPersistenceConfiguration class and LogPersistenceEvaluationMode enum in both Elsa.Api.Client and Elsa.Workflows.Runtime. Updated JavaScript services to handle enums correctly and register LogPersistenceMode.

* Rename log persistence key for consistency

Updated the log persistence key from `LogPersistenceStrategyKey` to `LogPersistenceConfigKey` to maintain consistency across the codebase. This change ensures that property access aligns with the updated naming conventions used in the application's configuration.

* Reuse JSON serializer options

* Update log persistence config structure in comments

This commit revises the JSON example in code comments to reflect the updated structure of the log persistence configuration. The changes include updated evaluation modes and strategy types for default, inputs, and outputs sections. These modifications aim to enhance clarity and provide accurate documentation of the expected configuration format.
2024-11-28 12:19:38 +01:00