Commit graph

136 commits

Author SHA1 Message Date
copilot-swe-agent[bot] 8c1618b5d4
Address latest health check review feedback
Agent-Logs-Url: https://github.com/elsa-workflows/elsa-core/sessions/6a652ca4-f0c8-4284-938d-6de0eb7a2bea

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
2026-05-20 23:39:21 +00:00
Sipke Schoorstra 09641c1fab
Keep root health check as liveness probe 2026-05-21 01:32:03 +02:00
Sipke Schoorstra a0d6f6b24b
Address health check review feedback 2026-05-21 01:18:07 +02:00
Sipke Schoorstra f149c27ab0
Address health check review feedback 2026-05-21 00:09:46 +02:00
Sipke Schoorstra 182f524d83
Harden readiness health check reporting 2026-05-20 23:43:25 +02:00
Sipke Schoorstra a8390d8d64
Address health check review feedback 2026-05-20 13:47:39 +02:00
Sipke Schoorstra 1e41f6fdf8
Add Elsa runtime readiness health checks 2026-05-20 13:34:25 +02:00
Sipke Schoorstra ab3e46bbe2
[codex] Add live server log streaming diagnostics (#7438)
* Add live server logs Spec Kit plan

* Implement live server logs diagnostics module

* Add server log sources and redaction hardening

* Add diagnostics unit tests

* Harden server log hub subscriptions

* Secure server log hub permissions

* Validate server log filter updates

* Add diagnostics logger and source tests

* Add diagnostics integration test project

* Add multi-source diagnostics provider coverage

* Broadcast server log source changes

* Document diagnostics server log streaming

* Add diagnostics sample host wiring

* Record diagnostics validation results

* Address server log PR feedback

* Rename diagnostics module to server logs

* Add server logs shell feature

* Make server logs shell options bindable

* Accept read wildcard for server logs

* Align server logs authorization with API patterns

* Update CShells structure and logging levels, add diagnostics module

* Rename PostgreSql shell feature classes for consistency

* Switch from Sqlite to PostgreSQL for workflow and identity persistence, add QuartzPostgreSql configuration

* Refactor server logs into diagnostics structured logs (#7440)

* Specify diagnostics structured logs refactor

* docs: clarify structured logs spec

* docs: plan diagnostics structured logs

* docs: add diagnostics structured logs tasks

* refactor: rename server logs to diagnostics structured logs

* Refactor PostgreSql persistence features to use centralized entity model handler registration.

* Refactor EFCore persistence features to centralize entity model handler registration for MySql, Sqlite, and Oracle providers.

* Integrate structured logs by renaming server logs, adjusting appsettings, and updating project references.

* Switch from PostgreSQL to Sqlite for workflow and identity persistence, update appsettings configuration.
2026-05-11 00:08:52 +02:00
Sipke Schoorstra c60e63c3c6
Integrate shells (#7279)
* Add CShells package references and integrate shell features into the application

* Annotate shell features with `[ShellFeature]` attribute and update `TempElsaFeature` to use `ConfigureElsa`.

* Revert "Annotate shell features with `[ShellFeature]` attribute and update `TempElsaFeature` to use `ConfigureElsa`."

This reverts commit e8a875e8f9d14891c5403df50e8ac7e151db25dd.

* Introduce `Elsa.ModularServer.Web` with a minimal API, restructure shell feature configuration, and remove obsolete `CShells` dependency

* Update `CShells` package references, add Fody weaver, and configure new CShells package sources in `NuGet.Config`.

* Adds CShells integration to Elsa

Integrates CShells to enhance modularity and extensibility.

- Adds CShells related projects to the solution.
- Updates NuGet configuration to include CShells preview feed.
- Creates initial app settings for CShells configuration.
- Adds CShells.AspNetCore project reference.
- Implements CShells extensions in the program file.
- Creates shell feature classes in Elsa.Common.
- Creates shell feature classes in Elsa.Expressions.
- Creates shell feature classes in Elsa.Workflows.Core.
- Creates shell feature classes in Elsa.Workflows.Management.
- Creates shell feature classes in Elsa.Workflows.Runtime.
- Creates shell feature classes in Elsa module.

* Refactor CShells: enhance pipeline configuration and features

Consolidated updates to CShells including a new `ResolverPipelineBuilder` for customizable resolver strategy pipelines. Improved assembly scanning, error handling in web routing, and streamlined shell feature dependencies for better clarity and functionality.

* Add feature registration system and FastEndpoints integration

Introduced a feature registration infrastructure with `IInstalledFeatureProvider` and related implementations. Added shell-based feature configurations such as caching, SAS tokens, workflows management, and a FastEndpoints integration module to support dynamic API registration.

* Refactor shell routing and enhance global route handling

Refactored `ShellEndpointRouteBuilder` to simplify initialization and support a combined shell/global route prefix. Enhanced `ShellEndpointRegistrationHandler` to include global route prefix logic and improved feature discovery using pre-resolved descriptors. Updated `Program.cs` for consistent middleware setup.

* Refactor feature endpoints to use `IInstalledFeatureProvider` for improved dependency management and simplified implementation

* Add display names, descriptions, and dependency enhancements to shell features

Standardized `ShellFeature` attributes across `ElsaFeature`, `WorkflowRuntimeFeature`, and `WorkflowManagementFeature` by adding display names, descriptions, and improving dependency declarations. Updated `ElsaFeature` to register `IInstalledFeatureProvider` for feature bridging.

* Add FastEndpoints references and update package versions

Added project references to CShells.FastEndpoints and related projects in multiple csproj files. Updated FastEndpoints package versions in `Directory.Packages.props` for compatibility with .NET 8/9/10. Removed obsolete folder references from Elsa.Caching.csproj and refined the namespace in CShells.AspNetCore.Abstractions.

* Add Identity and DefaultAuthentication features to appsettings.json configuration

* Add project references for Elsa.Identity and CShells.FastEndpoints.Abstractions

* Add `Identity` and `DefaultAuthentication` shell features with enhanced authentication and authorization support

* Set default signing key in `IdentityTokenOptions` for identity configuration

* Add service exclusion infrastructure for shell-specific contexts

Introduce `IShellServiceExclusionProvider` and `IShellServiceExclusionRegistry` to manage excluded service types per-shell. Implement ASP.NET Core-specific providers for authentication and authorization to enable shell-specific configurations. Refactor `DefaultShellHost` to use the new exclusion registry for service inheritance filtering.

* Refactor CShells authentication and authorization APIs

Renamed and unified methods for shell authentication and authorization and added a new combined method `WithAuthenticationAndAuthorization`. Enhanced `AddShells` to automatically register a default configuration provider if none is specified. Updated usage in Elsa.ModularServer to utilize the new API.

* Add Elsa-specific FastEndpoints configurator and feature

Introduce `ElsaFastEndpointsConfigurator` to customize FastEndpoints serialization and value parsing for Elsa workflows. Register this functionality through the new `ElsaFastEndpointsFeature`, which integrates with the shell's dependency injection system using an `IFastEndpointsConfigurator` interface.

* Update Workflow API feature dependency to `ElsaFastEndpoints`

* Pass `cancellationToken` to `ReadToEndAsync` in `PostEndpoint` for improved request handling.

* Add project references for CShells.AspNetCore and CShells.FastEndpoints.Abstractions

* Update CShells package versions to `0.0.6-preview.30` and add `CShells.FastEndpoints.Abstractions`

* Configures shell routing and features

Enables path routing for shells to allow proper routing within each shell.

Configures the ElsaFastEndpoints feature to depend on the FastEndpoints feature.
This ensures that FastEndpoints is properly configured before Elsa's FastEndpoints configurations are applied.

Registers activity types within the WorkflowManagementFeature.
This ensures activities are available for workflow construction and execution.

* Add shell lifecycle management and notification handlers

Introduced interfaces and handlers for shell activation (`IShellActivatedHandler`) and deactivation (`IShellDeactivatingHandler`) to manage shell lifecycles. Added `ShellStartupHostedService` to coordinate shell activation on startup and deactivation on shutdown. Updated notification system to support new shell lifecycle events and renamed existing notification records for consistency.

* Introduces EF Core persistence layer

Adds base classes and implementations for EF Core persistence, including database provider configuration and shell feature integration.

This change introduces a generic approach to configuring EF Core persistence for various Elsa modules, promoting code reuse and simplifying the process of supporting different database providers.

It includes:

- Base classes for database provider configurators and shell features.
- Implementations for Sqlite, SQL Server, MySql, PostgreSql, and Oracle.
- Shell features for Alterations, Identity, Labels, Management (Workflow Definitions and Instances), Runtime, and Tenants modules.

* Add comprehensive feature configuration validation system

Introduce a feature configuration system with support for binding, auto-configuration, and validation using DataAnnotations, FluentValidation, and composite patterns. Includes new validators, binding logic, and extensions to simplify configuration tasks while ensuring robustness and flexibility.

* Add persistence shell features for MySql, Oracle, PostgreSql, and Sqlite

Introduced new shell features to configure MySql, Oracle, PostgreSql, and Sqlite persistence for workflow definitions and runtime data. Updated `appsettings.json` to replace individual Sqlite features with a unified `SqliteWorkflowPersistence`. Made minor code cleanup in `FastEndpointsFeature`.

* Configure shell features for persistence

Added `IServiceCollection` configuration for MySql, Oracle, PostgreSql, and Sqlite shell features to set up persistence services.

* Remove DatabaseProviderConfigurators and refactor persistence shell features

Deleted DatabaseProviderConfigurator classes and restructured persistence shell features by integrating direct configuration logic for MySql, Oracle, PostgreSql, Sqlite, and SqlServer. Simplified configuration by inheriting from abstract shell feature base classes and removed redundant code.

* Correct IWorkflowDefinitionPublisher registration to use WorkflowDefinitionPublisher implementation

* Add resilience feature and scoped services configuration for Sqlite persistence

- Integrated `Microsoft.Extensions.DependencyInjection` to shell features for Sqlite persistence.
- Updated `appsettings.json` and project references to include a new 'Resilience' feature.
- Changed `ICommitStateHandler` service registration in `WorkflowRuntimeFeature` to use an implementation.

* Add `ResilienceShellFeature` for configuring resilience strategies

- Implemented new `ResilienceShellFeature` class to manage services related to resilience features.
- Added scoped and singleton service registrations for resilience strategies, exception detection, and activity invocation.
- Configured expression options for resilience handling in workflows.

* Add new shell features: Alterations, Blob Storage, Caching, Clustering, CSharp, Distributed Runtime, ElsaScript, Flowchart, HTTP, JavaScript, Key-Value, and Labels

* Switch project references to package references for CShells libraries and update to version 0.0.7.

* Potential fix for pull request finding 'Call to 'System.IO.Path.Combine' may silently drop its earlier arguments'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>

* Fix shell feature discovery and remove duplicate service registrations (#7285)

* Initial plan

* Address PR review comments: Add ShellFeature attributes, fix duplicates, and improve security

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Update dependencies and fix scoped services registration in `WorkflowRuntimeFeature`

* Fix null reference and typo in shell feature provider (#7286)

* Initial plan

* Fix null StartupType guard in Find() and typo in variable descriptor

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

---------

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
2026-02-12 20:30:02 +01:00
Sipke Schoorstra 7bc9035f5e
Implement null TenantId for tenant-agnostic entities (#7226)
* Add ADR for Null Tenant ID, implement tenant-agnostic logic

Introduce ADR-0009 to document the use of `null` for tenant-agnostic entities, enhancing multitenancy handling. Update multitenancy features across the codebase, including EF Core query filters and ActivityRegistry, to handle null as a tenant ID, ensuring tenant-agnostic entities are accessible across all tenants.

* Add multitenancy support in `ActivityTestFixture` by registering `ITenantAccessor`.

* Update src/modules/Elsa.Common/Multitenancy/Implementations/DefaultTenantAccessor.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Remove unused `using Elsa.Common.Multitenancy;` from WorkflowDefinitionActivityDescriptorFactory (#7230)

* Initial plan

* Remove unused using Elsa.Common.Multitenancy statement

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Optimize ActivityRegistry.Find to prefer tenant-specific descriptors without performance regression (#7227)

* Initial plan

* Optimize Find(string type) to prefer tenant-specific descriptors with single-pass iteration

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Apply review feedback: combine if statements and add comprehensive unit tests

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Refactor tests for DRYness using theories and helper methods

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Clean up extra whitespace in test file

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Fix default tenant data visibility leak by removing NullIfEmpty conversion (#7229)

* Initial plan

* Remove NullIfEmpty conversion to align with ADR-0008 and ADR-0009

- Updated ElsaDbContextBase to use empty string for default tenant
- Updated ApplyTenantId to stop converting empty string to null
- Updated TenantAwareDbContextFactory to preserve empty string for default tenant
- Updated Store.cs to preserve empty string for default tenant
- This ensures: null = tenant-agnostic (visible to all), "" = default tenant

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Add database migration to convert null TenantId to empty string for SqlServer

- Added Management migration to convert null to "" for WorkflowDefinitions and WorkflowInstances
- Added Runtime migration to convert null to "" for all runtime entities
- This ensures existing default tenant data is properly migrated per ADR-0008
- Note: Similar migrations needed for PostgreSql, MySql, Sqlite, and Oracle providers

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Clarify tenant handling logic in `ElsaDbContextBase` with new ADR references.

* Add tenant ID convention analysis documents and quick reference guide

* Implement tenant-agnostic functionality across modules

- Introduce `AgnosticTenantId` constant to manage tenant-agnostic entities.
- Modify entity handling logic to respect tenant-agnostic designations.
- Adjust workflow processing to include tenant-agnostic workflows.
- Update caching and activity descriptor logic to accommodate the `AgnosticTenantId`.

* Refactor tenant management and registry logic in `ActivityRegistry` for improved clarity and separation of tenant-specific and tenant-agnostic activity descriptors. Remove `TestTenantResolver` and update workflow definition handling for tenant support.

* Refactor `ActivityRegistry`: prioritize tenant-specific descriptors over tenant-agnostic and simplify descriptor retrieval logic.

* Improve async handling in `CommandHandlerInvokerMiddleware` to await tasks without blocking

* Update ADR to use asterisk as sentinel value for tenant-agnostic entities

Replace the previous convention of using `null` for tenant-agnostic entities with an asterisk (`"*"`) for improved clarity and system architecture. Updated ADR documentation, TOC, and dependency graph accordingly.

* Remove migration `ConvertNullTenantIdToEmptyString` and its associated designer file to clean up the codebase.

* Refactor `ActivityRegistry`: streamline activity descriptor removal logic and simplify tenant ID checks.

* Update Elsa.sln

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Simplify `RefreshDescriptorsAsync` by removing unnecessary local variable `currentTenantId`.

* Remove unused `currentTenantId` variable from `ActivityRegistry`.

* Add detailed semantic flow and key points to ADR 0009

Document the tenant ID flow from entity creation to query, emphasizing normalization and tenant-agnostic workflows. Update semantic flow diagrams and provide testing considerations for preserving `"*"` values in multi-tenant scenarios.

* Remove outdated Tenant ID Analysis and associated documents

* Add security-by-default design for tenant-agnostic entities in ADR

Enhance Architecture Decision Record to detail explicit requirements for tenant-agnostic database entities, highlighting differences between in-memory activity descriptors and persistent entities. Emphasize importance of setting `TenantId = "*"` to prevent accidental data leakage.

* Normalize tenant ID grouping in `ActivityRegistry` to unify null and agnostic IDs, reducing redundant processing.

* Refactor `SignalManager`: improve timeout handling and streamline signal task cancellation.

* Update src/modules/Elsa.Workflows.Core/Models/TenantRegistryData.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/modules/Elsa.Workflows.Core/Services/ActivityRegistry.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Refactor tests to use `Tenant.AgnosticTenantId` instead of `null` for tenant-agnostic descriptors.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Enhance logging in recurring tasks: add error handling and logger support to prevent crashes in scheduled timers.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
2026-02-02 10:59:01 +01:00
Sipke Schoorstra afe33baf01
Disable multitenancy and update deletion process in component tests:
- Set `useMultitenancy` to `false` in `Program.cs`.
- Remove tenant filtering from `WorkflowDefinitionActivityProvider`.
- Enhance `DeleteWorkflowTests` by ensuring registry refresh without delay.
- Adjust tenant configuration in `DeleteWorkflow` for test accuracy.
- Lower `Threshold` in test project and update GitHub Actions versions.
2026-01-31 00:09:19 +01:00
Sipke Schoorstra b09a564812
Fix Multitenancy Support and Normalize Tenant ID Handling (#7217)
* Enable multitenancy support and normalize tenant ID handling.

- Activate multitenancy in `Program.cs`.
- Introduce `NormalizeTenantId` method for consistent tenant ID usage.
- Update tenant-related classes and features to support normalization logic.

* Add ADR for adopting empty string as the default tenant ID

- Standardized the tenant ID for the default tenant to use an empty string (`""`) instead of `null`.
- Documented the rationale and migration considerations in ADR 0007.
- Updated ADR table of contents and graph for new entry.

* Apply suggestion from @sfmskywalker

* Update doc/adr/graph.dot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Normalize spacing and improve readability in `Program.cs`. Fix multitenancy condition formatting.

* Fix ADR numbering and update TOC

* Add ADRs for flowchart execution model, tenant deletion event, merge modes, and default tenant ID

- Introduced ADR 0005: Token-centric flowchart execution model for improved loop and join handling.
- Added ADR 0006: Tenant Deleted event for distinct handling of tenant removal.
- Documented ADR 0007: Explicit merge modes for flowchart joins, improving reliability and configurability.
- Included ADR 0008: Standardization of empty string as the default tenant ID for consistency and clarity.

* Add unit tests for tenant ID normalization and multitenancy pipeline invoker

- Added comprehensive unit tests for tenant ID normalization to ensure consistent handling of null, empty, and valid IDs.
- Introduced tests for the multitenancy pipeline invoker covering various tenant resolution scenarios.
- Updated solution to include new unit testing projects for `Elsa.Tenants` and `Elsa.Common`.

* Update unit tests for `ActivityConstructionResult`

- Refactor test parameterization to verify `HasExceptions` property more explicitly.
- Simplify exception creation logic in helper methods.
- Improve test assertions by combining act and assert phases where applicable.

* Enable configuration-based multitenancy with tenant-specific settings

- Introduced a configuration-based tenant provider to streamline tenant initialization and customization.
- Added tenant ID handling filters to ensure tenant ID is applied and filtered automatically.
- Deprecated the `CommonPersistenceFeature` in favor of modular persistence feature extension.

* Update database indexes to include `TenantId` for multitenancy support

- Added `TenantId` to unique constraints on `Triggers` table across all EFCore providers.
- Adjusted index names to reflect the updated constraints.
- Updated trigger configuration to ensure uniqueness includes `TenantId`.

* Add tenant filtering to `DefaultWorkflowDefinitionStorePopulator`

- Introduced `ITenantAccessor` to support tenant-specific filtering of workflow definitions.
- Updated logic to skip workflows not matching the current tenant.

* Update doc/adr/toc.md

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Remove `CommonPersistenceFeature` as it has been deprecated

* Add tenant-specific filtering to workflow import logic in `DefaultWorkflowDefinitionStorePopulator`

* Replace hardcoded tenant ID with `Tenant.DefaultTenantId` in integration tests

* Update database indexes and migration logic to support `TenantId` for multitenancy

- Added `TenantId` to unique constraints on the `Triggers` table and updated index names.
- Included logic to drop outdated indexes without `TenantId` during migration.
- Adjusted tests to account for `TenantId` in workflow identity and indexing scenarios.

* Remove `TenantId` from workflow identity construction in concurrent trigger indexing tests

* Introduce `SelectiveMockLockProvider` for precise lock mocking in tests

- Added `SelectiveMockLockProvider` to allow targeted lock mocking without affecting unrelated background operations.
- Updated test services to use `SelectiveMockLockProvider` in place of `TestDistributedLockProvider`.
- Refactored `DistributedLockResilienceTests` to support selective mocking for deterministic and reliable assertions.

* Update Elsa.sln

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Normalize tenant ID handling in `DefaultWorkflowDefinitionStorePopulator` for consistent filtering

* Refactor `TenantResolverResult` to support explicit resolved/unresolved state handling

- Updated `TenantResolverResult` to include an explicit `_isResolved` property.
- Adjusted `ResolveTenantId()` and `IsResolved` logic for improved clarity and robustness.
- Simplified tenant resolution invocation in `TenantResolverBase`.
- Removed redundant normalization in `DefaultTenantResolverPipelineInvoker`.

* Normalize tenant ID handling in `DefaultWorkflowDefinitionStorePopulator` and `ClrWorkflowsProvider`.

* Refactor `DefaultWorkflowDefinitionStorePopulatorTests`: streamline object initializations and add tenant-specific test coverage for `PopulateStoreAsync`.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-01-30 19:54:13 +01:00
Sipke Schoorstra fa04e1ebcd
Adds activity host registration support (#7172)
* Add support for activity host registration across workflows

Introduced new APIs and updates to enable registering custom activity hosts in the workflow management system. This includes modifications to attributes, service registrations, and extensions to streamline integration for advanced activity hosting scenarios.

* Remove unused `using` directives across Workflow Management module

* Add support for host method activity registration and description

Introduce new APIs to enable activity registration from public async methods (Task/Task<T>) on CLR types. Includes `HostMethodActivitiesOptions`, `HostMethodActivity`, `HostMethodActivityProvider`, and `HostMethodActivityDescriber` for dynamic activity generation and execution.

* Refactor host method activity execution and cleanup.

Reworked `HostMethodActivity` to support resumable workflows, improved parameter handling with pluggable value providers, and removed obsolete `AgentExecutionContext`. Enhanced method resolution, async handling, and input/output descriptor logic for better flexibility and maintainability.

* Refactor `Bookmark` model to use mutable properties and update XML documentation.

* Refactor `BookmarkExecutionContextExtensions` to improve structure, add `GenerateBookmarkTriggerToken` method, and enhance maintainability.

* Add extensibility for host method parameter binding with pluggable value providers

Introduced `IHostMethodParameterValueProvider` interface for custom parameter resolution, along with `DefaultHostMethodParameterValueProvider`, `DelegateHostMethodParameterValueProvider`, and `FromServicesAttribute` for flexible binding options. Enhances host method activity execution by supporting DI resolution and workflow input handling.

* Refactor nullable usage and improve bookmark management logic

Updated null assignment for consistency across files and refined logic for detecting and handling newly added bookmarks. Adjusted method signatures and parameters in the DecoratedStoryWriterAgent class for more explicit input handling. These changes enhance code readability, maintainability, and robustness.

* Update src/modules/Elsa.Workflows.Management/Activities/CodeFirst/HostMethodActivityProvider.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Ensure `CallbackMethodName` is set and skip bookmarks with empty values

* Update src/modules/Elsa.Workflows.Management/Features/WorkflowManagementFeature.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/modules/Elsa.Workflows.Management/Contracts/IHostMethodActivityDescriber.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/modules/Elsa.Workflows.Core/Attributes/InputAttribute.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Refactor `CodeFirst` namespace to `HostMethod` for improved clarity and align with updated activity execution logic. Enhance DI-based parameter resolution and update XML documentation for `HostMethodActivitiesOptions`.

* Add `Penguin` activity host with sample activity methods and register in Elsa pipeline

* Add `TestHostMethod` activities and corresponding component tests. Register `TestHostMethod` as an activity host in the workflow server.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-27 20:52:52 +01:00
Sipke Schoorstra 9e6144922c
Adds ILoggerFactory support to converters (#7153)
* Refactor `Send.OkAsync` calls to use named `cancellation` parameter for consistency. Update `Finish.cs` to explicitly reference `WorkflowExecutionContext` when clearing callbacks.

* Add `ILoggerFactory` support to Flowchart and Connection converters

Refactor `FlowchartJsonConverter` and `ConnectionJsonConverter` to accept `ILoggerFactory` via dependency injection. Update methods to enhance logging for missing activities and connections. Convert static methods to instance methods, and introduce nullability checks for connections. Update `WorkflowExecutionContext` to expose public callbacks management APIs.

* Switch Flowchart execution to Token-Based strategy and refine null checks in ConnectionJsonConverter

* Refactor `ConnectionJsonConverter` to improve object initialization and formatting consistency

* Improve logging and nullability handling in `ConnectionJsonConverter`

Enhance logging for missing source or target activities by leveraging `_logger` for additional context. Refine null checks for source and target activity retrieval. Simplify object initialization and clean up redundant code.

* Refine null checks in `ConnectionJsonConverter` for improved safety

* Correct initialization of `Connection` object in `FlowchartJsonConverter`.

* Update src/modules/Elsa.Workflows.Core/Activities/Flowchart/Serialization/FlowchartJsonConverter.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Remove redundant whitespace in `ConnectionJsonConverter` constructor.

* Remove redundant whitespace in `FlowchartJsonConverter`.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-19 21:54:20 +01:00
Sipke Schoorstra 4bbdd6f3a7
Configures Flowchart Execution via DI (#7141)
* Introduce `FlowchartExecutionMode` to streamline flowchart execution logic.

- Added `FlowchartExecutionMode` enum to represent execution modes (Default, TokenBased, CounterBased).
- Updated flowchart-related integration and unit tests to use the new execution mode.
- Removed the global `UseTokenFlow` flag in favor of execution-specific configuration via `RunWorkflowOptions`.
- Refactored flowchart-related APIs and test helpers for improved flexibility and modularity.

* Add support for configuring flowchart execution behavior via `FlowchartOptions` and DI.

- Introduced extensions for `FlowchartFeature` to simplify configuration.
- Added DI support for setting default execution modes.
- Refactored flowchart execution logic to prioritize configuration.

* Update default Flowchart execution settings to align with version 3.5.2 behavior

- Changed `DefaultExecutionMode` to `CounterBased`.
- Updated `UseTokenFlow` default to `false`.

* Update src/modules/Elsa.Workflows.Core/Activities/Flowchart/Models/FlowchartExecutionMode.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/modules/Elsa.Workflows.Core/Activities/Flowchart/Extensions/FlowchartFeatureExtensions.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update test/integration/Elsa.Workflows.IntegrationTests/Scenarios/FlowchartNextActivity/Tests.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/modules/Elsa.Workflows.Core/Activities/Flowchart/Extensions/RunWorkflowOptionsExtensions.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Refactor flowchart integration tests for improved formatting and consistency

* Refactor workflow tests and related services to improve reusability and align with updated Flowchart execution behavior

* Update src/modules/Elsa.Workflows.Core/Activities/Flowchart/Options/FlowchartOptions.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Refactor flowchart execution logic to use `FlowchartExecutionMode` enum, replacing boolean checks for improved clarity and extensibility.

* Refactor tests and workflow logic to replace boolean `useTokenFlow` with `FlowchartExecutionMode` enum for clarity and consistency.

* Refactor flowchart execution logic to centralize mode-based behavior handling and simplify implementation.

* Remove unnecessary whitespace in Flowchart.cs to improve code formatting

* Remove unnecessary whitespace in FlowJoinTests.cs to improve code formatting

* Update src/common/Elsa.Testing.Shared.Integration/WorkflowTestFixture.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/Flowchart.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-15 10:15:39 +01:00
Sipke Schoorstra a1d4e541fc
Add Elsa Script DSL (#7076)
* Update packages.yml

* Update elsa-server-and-studio.yml

* Update elsa-server.yml

* Update elsa-studio.yml (#6715)

* Update ListWorkflowDefinitionsRequest.cs (#6761)

Remove unnecessary line breaks

* Correct namespace and import for `ConfigureEngineWithVariableTypes`.

* Resolves build issues, update package versions and restructure project references

- Updated multiple package versions in `Directory.Packages.props` for better dependency management, including `BenchmarkDotNet`, `FastEndpoints`, and `Microsoft.Extensions.Http.Resilience`.
- Minor version upgrade for `System.Formats.Asn1` in `_build.csproj`.
- Replaced project reference to `Elsa.csproj` with `Elsa.IO.Http.csproj` in `Elsa.ServerAndStudio.Web.csproj`, enhancing modularity.
- Added new using directive for `Elsa.IO.Http.Features` in `Program.cs` to support new HTTP functionalities.

* Remove unused project references from Elsa.sln

These changes indicate that the associated projects or dependencies are no longer needed or have been replaced by other components in the solution.

* Rename copilot-setup-steps.yml.yml to copilot-setup-steps.yml

* Update RawStringContent encoding in JsonContentFactory (#6786)

* Update RawStringContent encoding in JsonContentFactory

Modified the instantiation of `RawStringContent` to use a
new `UTF8Encoding` instance with `encoderShouldEmitUTF8Identifier`
set to `false`, affecting the handling of the UTF-8 byte order
mark (BOM) in serialized JSON content. Fixes a bug with content length being different than expected.

* Refactor JsonContentFactory to reuse UTF8Encoding

Introduced a private static readonly field `_utf8Encoding` in the `JsonContentFactory` class to improve code readability and performance. This change replaces the instantiation of `UTF8Encoding` in the `CreateHttpContent` method, allowing for the reuse of the same encoding instance.

---------

Co-authored-by: Max Brooks <Max@compyl.com>

* Enhance thread safety with ConcurrentDictionary usage (#6760)

* Enhance thread safety with ConcurrentDictionary usage

Replaced `IDictionary` with `ConcurrentDictionary` for
both `_scheduledTasks` and `_scheduledTaskKeys` to
improve thread safety in a multi-threaded environment.

Updated methods `RegisterScheduledTask`,
`RemoveScheduledTask`, and `RemoveScheduledTasks` to
utilize the `Remove` method of `ConcurrentDictionary`,
ensuring safe and efficient removal of scheduled tasks.

* Refactor task registration and removal logic

Updated `RegisterScheduledTask` to use `AddOrUpdate` for streamlined task management. This change simplifies the addition and updating of scheduled tasks by consolidating logic into a single operation. Introduced `RemoveScheduledTask` method to handle task removal by name, improving code organization and clarity.

* Improve task removal handling in LocalScheduler

Modified the `LocalScheduler` class to enhance the removal process of scheduled tasks from the `_scheduledTaskKeys` collection. The removal operation now captures the result in a variable and includes a conditional check to log a warning if the task was not found, improving error handling and debugging capabilities.

* Refactor task removal in LocalScheduler

Updated the removal process for scheduled tasks in `_scheduledTasks`.
The new implementation collects all corresponding keys and attempts to remove them individually, logging warnings for any failures. This enhances error handling and provides better debugging information.

---------

Co-authored-by: Max Brooks <Max@compyl.com>

* Add IAsyncEnumerable check to ItemSourceActivityExecutionContextExtensions.GetItemSource (#6897)

* Use FullName in WorkflowDictionary (#6923)

* Fixed ParentWorkflowInstanceId not being set (#7029)

Co-authored-by: Peter Klooster <peter.klooster@autotaalglas.nl>

* Remove unused solution projects and update package references

- Deleted several project references from `Elsa.sln` to clean up the solution.
- Updated `Directory.Packages.props` for consistency and alignment with the latest package versions.

* Simplify CI pipeline by removing `Test` step from `Compile+Test+Pack` process.

* Initial plan

* Add ElsaScript DSL module with parser and compiler

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Add integration tests for ElsaScript DSL

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Add comprehensive documentation for ElsaScript DSL

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Refactor workflow activity instantiation logic

- Removed `ActivityFactory` and its related interfaces and extensions.
- Introduced `ActivityActivator` for handling activity creation.
- Extended AST with support for comprehensive workflow structures:
  - Added nodes for flowcharts, if/else, loops, and variable declarations.
- Updated `IElsaScriptCompiler` to use asynchronous methods.
- Expanded `ElsaScriptParser` to simplify syntax for `UseNode` and argument parsing.
- Adjusted compiler and parser for compatibility with new workflow AST model.

* Refactor test method names for clarity and add new compiler and parser tests

- Updated method names in `CompilerTests` and `ParserTests` for better readability and description of test intent.
- Added tests for compiler and parser:
  - Support for workflows without the `workflow` keyword.

* Refactor `ElsaScriptParser` to improve statement parsing and introduce a tokenizer

- Added `TokenizeStatements` method to split source into statements for enhanced parsing accuracy.
- Updated logic to process statements instead of raw lines, reducing parsing complexity and improving reliability.
- Improved handling of workflow and statement parsing, including edge cases with braces, parentheses, and string literals.

* Introduce ElsaScript support for BlobStorage workflow provider

- Added the `Elsa.WorkflowProviders.BlobStorage.ElsaScript` module to enable ElsaScript-based workflow definitions for BlobStorage.
- Implemented `ElsaScriptBlobWorkflowFormatHandler` for parsing ElsaScript workflows stored in BlobStorage.
- Extended `ElsaScriptParser` to leverage Parlot for improved DSL parsing.
- Introduced `IBlobWorkflowFormatHandler` to centralize workflow format handling and parsing.
- Updated `Elsa.Server.Web` to reference the new module and include an ElsaScript "Hello World" example workflow.

* Refactor ElsaScript services, update logging, and improve workflow handling

- Changed `ElsaScriptCompiler` service registration from `Singleton` to `Scoped` for better dependency management.
- Enhanced the "Hello World" example workflow and added `CopyToOutputDirectory` configuration.
- Removed unused namespaces and adjusted references in multiple projects to improve maintainability.
- Updated logging levels in `appsettings.json` to reduce unnecessary debug output.
- Improved `PolymorphicObjectConverter` by removing redundant dependencies.
- Added missing references to enhance feature support and ensure compatibility.

* Refactor activity instantiation and improve argument handling in `ElsaScriptCompiler`

- Added support for positional arguments with constructor matching logic.
- Refactored `InstantiateActivityUsingConstructor` to enhance activity creation.
- Updated `ActivityDescriptor` and related types to include `ClrType` for streamlined activity resolution.
- Simplified `TypedActivityProvider` by annotating it with `[UsedImplicitly]`.
- Adjusted `ElsaScriptParser` to remove unnecessary options from string literal definitions.

* Add HTTP-enabled "Hello World" workflow and support for additional HTTP activity constructors

- Introduced a new ElsaScript example workflow `hello-world-http.elsa` with an HTTP endpoint and response.
- Enhanced `HttpEndpoint` and `WriteHttpResponse` activities with additional constructors for improved flexibility.
- Updated project to include the new workflow in the output directory.

* Enhance `ElsaScriptParser` with a custom parser to handle nested raw expressions for ElsaScript workflows

- Introduced `RawExpressionParser` to parse raw text after `=>` up to a matching closing parenthesis.
- Updated `elsaExpressionWithLang` and `elsaExpressionWithoutLang` to use `RawExpressionParser`.
- Trimmed whitespace in parsed expressions.
- Added integration and parser tests for complex workflows with variables and expressions.
- Updated example workflow `hello-world-http.elsa` to demonstrate expression usage.
- Added `Elsa.Http` module reference to enable HTTP-based activities.

* Update "Hello World" workflow to simplify naming and enhance response logic

- Renamed workflow from `HelloWorldHttpDsl2` to `HelloWorldHttpDsl`.
- Updated HTTP endpoint path to `/hello-world-dsl` for consistency.
- Improved response logic by utilizing `getMessage()` JavaScript function.

* Add support for `OriginalSource` in workflow materialization and enhance ElsaScript materializer

- Introduced `OriginalSource` property in `WorkflowDefinition` and `MaterializedWorkflow` for preserving original source representation (e.g., ElsaScript, JSON, YAML).
- Added `ElsaScriptWorkflowMaterializer` implementation to materialize workflows directly from ElsaScript source.
- Updated `DefaultWorkflowDefinitionStorePopulator` to determine `StringData` or `OriginalSource` based on materialized workflow format.
- Enhanced `WorkflowDefinitionMapper` to support symmetric round-tripping with `OriginalSource`.
- Registered `ElsaScriptWorkflowMaterializer` in `ElsaScriptFeature` for dependency injection.
- Updated `JsonBlobWorkflowFormatHandler` and added `OriginalSource` support for round-trip preservation.
- Simplified `ElsaScriptParser` by aligning variable and parser naming.

* Update V3_6 migrations for PostgreSQL, MySQL, and Oracle databases and associated designer files.

* Handle disposal and race conditions in `ScheduledCronTask`

- Added `_disposed` flag to prevent accessing disposed resources.
- Updated `_executionSemaphore` and `_scopeFactory` logic to safely handle `ObjectDisposedException`.
- Enhanced task scheduling and timer disposal with additional safeguards against race conditions.
- Modified tests to ensure proper disposal and logging behavior when handling edge cases.

* Add support for metadata in ElsaScript workflows and enhance parser and compiler functionality

- Introduced metadata syntax in ElsaScript workflows (e.g., `DisplayName`, `Description`, `Version`) to enable metadata-driven behavior.
- Enhanced `ElsaScriptCompiler` to process metadata and properly integrate it into `Workflow` objects.
- Updated `ElsaScriptParser` to parse program-level AST with support for multiple workflows and global use statements.
- Refactored tests to validate metadata parsing and ensure backward compatibility with existing workflows.
- Added new test cases to cover scenarios like metadata parsing, compilation, and multi-workflow programs.

* Add support for `foreach` loops in ElsaScript and remove `let` keyword

- Introduced `foreach` loop syntax in `ElsaScriptParser` and `ElsaScriptCompiler`, enabling iteration over collections with optional variable declaration.
- Updated `ForNode` and `ForEachNode` to include a `DeclaresVariable` flag for improved variable handling.
- Removed support for the `let` keyword in variable declarations, streamlining syntax to use `var` and `const` only.
- Enhanced `for` loop syntax to support optional `var` declaration and block or single-statement bodies.
- Refactored test cases to validate `foreach` and `for` loop enhancements and ensure backward compatibility.

* Simplify ElsaScript workflow syntax by removing redundant quotes in workflow identifiers and updating `for` loop syntax for clarity and consistency.

* Remove redundant quotes from workflow identifiers in integration tests

* Simplify Elsa scripts and improve error handling

- Removed redundant braces in workflow declarations for streamlined syntax.
- Enhanced logging in `JsonBlobWorkflowFormatHandler` and `ElsaScriptBlobWorkflowFormatHandler` to warn on parsing errors and provide context.
- Updated configuration to log errors for `Elsa.Workflows.ActivityRegistry`.
- Refined "Hello World" and "For Loop" workflows for clarity and added improved loop handling.

* Refine Elsa workflows and update compiler logic

- Simplified "Hello World" workflow by adding braces and improving consistency.
- Adjusted "For Loop" workflow to rename and clarify logic, including expression updates and variable handling.
- Fixed compiler mapping of `"cs"` to `"CSharp"` for better clarity.
- Enhanced "Hello World HTTP" workflow to correctly reference `variables.message` in expressions.

* Add flowchart support in ElsaScript parser, compiler, and integration tests

- Introduced `flowchart` syntax in `ElsaScriptParser` to support flowchart-based workflows.
- Updated `ElsaScriptCompiler` to compile `flowchart` nodes with labeled activities, connections, entry points, and variables.
- Added integration tests for parsing and compiling empty and simple flowcharts.
- Enhanced `FlowchartNode` and `LabeledActivityNode` for better representation of flowchart structures.
- Improved error handling and logging for invalid flowchart configurations.

* Add tests for compiling and parsing flowcharts with nodes, connections, and block nodes in ElsaScript

- Added integration tests for compiling and validating flowchart structures, including activities, connections, and entry points.
- Implemented parser tests for parsing flowcharts with node connections and block nodes.
- Updated project files to include new workflow examples for testing.

* Add Parlot package and update project file in integration tests

- Added `Parlot` package version `0.0.27` to `Directory.Packages.props`.
- Updated integration test project file to include a new `Include` directive for better targeting.

* Update Parlot package to version 1.5.2 in Directory.Packages.props

* Remove `elsa-server-and-studio.yml` workflow and update solution file

- Deleted `elsa-server-and-studio.yml` workflow as it's no longer needed.
- Updated `Elsa.sln` to remove reference to the deleted workflow.

* Remove `elsa-studio.yml` workflow and update solution and packages

- Deleted `elsa-studio.yml` workflow as it's no longer used.
- Updated `Elsa.sln` to remove reference to the deleted workflow.
- Changed `base_version` in `packages.yml` from `3.7.0` to `3.6.0`.

* Downgrade Docker image in `elsa-server.yml` workflow from `v3.7.0-preview` to `v3.6.0-preview`

* Update Docker image tag in `elsa-server.yml` workflow from `v3.6.0-preview` to `v3.6-preview`

* Add logging support to `LocalScheduler` and replace `Debug.WriteLine` with `ILogger`

* Remove unused `System.Collections.Generic` and `Elsa.Extensions` imports in `LocalScheduler`

- Cleaned up unnecessary using directives to improve code readability and maintainability.
- Minor whitespace adjustment for consistent formatting.

* Remove unnecessary whitespace in `LocalScheduler` for consistent formatting

* Improve exception handling in blob workflow format handlers

- Updated exception handling in `ElsaScriptBlobWorkflowFormatHandler` and `JsonBlobWorkflowFormatHandler` to gracefully catch and log all exceptions during workflow parsing.
- Adjusted comments to clarify behavior for invalid user-provided files, ensuring the workflow loading process is not disrupted.

* Refactor blob workflow format handlers to use `SupportedExtensions` for improved file filtering

- Added `SupportedExtensions` property to all blob format handlers to optimize blob storage browsing.
- Simplified `CanHandle` logic by removing extension checks, leveraging `SupportedExtensions` for initial filtering.
- Updated comments for clarity and consistency across handlers.

* Refactor `DefaultWorkflowDefinitionStorePopulator` to simplify `stringData` assignment logic and improve readability

* Remove outdated comment in `CompilerTests` about skipped tests

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Refactor `ElsaScriptCompiler` to streamline type conversion logic, improve language mapping, and enhance asynchronous flowchart compilation

* [WIP] Update ParseError printing based on feedback (#7082)

* Initial plan

* Fix ParseError formatting to use Message and Position properties

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Replace `as` casts with direct casts in ParserTests for null safety (#7083)

* Initial plan

* Replace 'as' casts with direct casts in ParserTests for better null safety

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Fix Oracle column types for OriginalSource and other large text fields (#7079)

* Initial plan

* Fix Oracle OriginalSource and StringData column types to handle large data

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Refactor tests to replace type checks with `Assert.IsType` for improved clarity and type safety

* Initial plan (#7080)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

* Add `Parlot` package reference and update solution structure by removing and reorganizing projects and workflows.

* Set default expression language to "JavaScript" in `ElsaScriptCompiler`.

* Add integration test to verify default expression language resets between ElsaScript compilations

* Simplify UTF-8 encoding in JsonContentFactory (#7081)

* Initial plan

* Remove explicit UTF8Encoding in JsonContentFactory and use Encoding.UTF8

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Fix test to use Encoding.UTF8.GetByteCount for multi-byte character support

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

---------

Co-authored-by: Ender <37611092+zengande@users.noreply.github.com>
Co-authored-by: Matt <knibbsy10@live.com>
Co-authored-by: Max Brooks <45081361+MaxBrooks114@users.noreply.github.com>
Co-authored-by: Max Brooks <Max@compyl.com>
Co-authored-by: FuJa0815 <30809803+FuJa0815@users.noreply.github.com>
Co-authored-by: Peter Klooster <crashkonijn@gmail.com>
Co-authored-by: Peter Klooster <peter.klooster@autotaalglas.nl>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-11-25 19:57:50 +01:00
Sipke Schoorstra aee09bb06f
Improves workflow deletion and task scheduling (#7088)
* 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.
2025-11-21 20:58:38 +01:00
Sipke Schoorstra 54af5ea714
Merge remote-tracking branch 'origin/patch/3.5.2' into develop/3.6.0 2025-11-11 17:01:22 +01:00
Sipke Schoorstra 32b04ded28
Enables distributed runtime for workflows
Configures the workflow runtime to use a distributed
implementation, enhancing scalability and resilience.

Adds debug logging for Elsa.
2025-11-04 20:34:04 +01:00
Sipke Schoorstra 42753359d2 Adjust recurring task schedules and bookmark queue TTL for optimized performance. 2025-10-06 15:39:16 +02:00
Sipke Schoorstra ff1f0833ad
Restore EF Core persistence layer (#6931)
* Restore EF Core persistence layer

Originally, we had moved EF Core to the extensions repo, but in practice this turned out to be rather impractical when debugging elsa-core, given that we would lose all of the state (workflow definitions, instances, etc.) across application restarts.

* Integrate PostgreSQL support into EF Core persistence and enhance BlobStorage workflows provider setup.
2025-09-27 20:39:18 +02:00
Sipke Schoorstra e5f52402ed
Add Elsa.Scheduling module and enable scheduling support in Elsa.Server.Web. 2025-09-25 22:49:32 +02:00
Lucas Hipólito 90b4e7d6c5
Initial implementation of log activity + base sink (#6859)
* Initial implementation of log activity + base sink

* Update src/modules/Elsa.ProcessLogging/Extensions/ModuleExtensions.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Refactor logging implementation: replace `Elsa.ProcessLogging` with a new modular `Elsa.Logging` framework, introducing support for configurable log sinks, enhanced logging extensibility, and updated dependencies in consuming projects.

* Enhance logging framework: introduce custom `NullableBoolConverter` and update JSON serialization/deserialization logic for log sink handling.

* Update description for `Log` activity input: clarify target sinks configuration

* Set default value of `SinkNames` input in `Log` activity to non-nullable collection

* Set `DisplayName` for `Sinks` input in `Log` activity

* Refactor logging framework: update `ILogSink` and `ILogSinkRouter` to support arguments and attributes, enhance `Log` activity to use updated interfaces, and add default category handling.

* Refactor logging framework: simplify argument handling in `ILogSink` and `ILogSinkRouter`, update `Log` activity inputs, and improve message formatting in `MelLogSink`.

* Update logging framework to simplify log sink creation, enhance category filtering, and refactor `ILogSink`/`ILogSinkRouter` interface methods.

* Introduce modular logging framework enhancements: add `Console` and `Serilog` logging features, refactor `ILogSink` framework, and update projects to align with a modular architecture.

* Refactor logging framework: introduce `AddCategoryFilters` extension, replace `DefaultCategory` handling with enhanced category filters, and update sink creation logic for consistency.

* Refactor logging framework: rename `SinkOptions` to `LogSinkOptions`, standardize naming across log sink types, and update configuration and sink factory logic for consistency.

* Enhance logging framework: add `ConfigureDefaults` methods, update `ILogSinkCatalog` to use `IServiceScopeFactory`, and improve logging configuration handling and defaults setup.

* Introduce asynchronous log entry processing: add `ILogEntryQueue`, `LogEntryBackgroundWorker`, and related models to enable queue-based logging and background processing. Update `Log` activity to enqueue log entries for processing.

* Add unit and integration tests for `Elsa.Logging.Core` library, refactor logger setup in `Elsa.Server.Web`, enhance logging configuration, and standardize `Directory.Packages.props` file.

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Add documentation comments to logging framework classes, interfaces, methods, and factories to enhance code readability and maintainability. Remove unused `CustomPurpleConsoleFormatter` class and `logs` folder from server project.

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Make `LogEntryInstruction` and `LogEntryQueue` classes public and simplify return statement in `LogSinkCatalog.ListAsync` method.

* Standardize terminology in `ILogSink` interface and `LoggerSink` implementation: rename `properties` to `attributes`. Update project files and solution structure to reflect integration test additions.

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update documentation comments in `LoggingFeature` and `LogEntryInstruction` to clarify functionality and improve precision.

* Add README for `Elsa.Logging` module with configuration examples, usage details, and extension guidance.

* Add `Dictionary` UI hint to `InputUIHints` and update `Attributes` in `Log` activity to use it.

* Update `Log` activity default category to "Process", add integration tests for logging, and enhance null safety in `ConfigurationLogSinkProvider`.

* Remove `UseLoggingFramework` middleware from `Program.cs` to streamline workflow initialization.

* Log Activity

* Auto stash before merge of "feat/6854-process-log-activity" and "patch/3.5.1"

* Refactor `LoggerSink` to simplify logging logic and remove unused `FormatMessage` method. Enhance `Log` activity argument handling by introducing JSON parsing for string inputs.

* Refactor logging tests to improve consistency and update variable initialization in `WorkflowExecutionContext` for cleaner syntax.

* Replace mocked logger dependencies in tests with `TestLogger` and `TestLoggerFactory` for improved readability and maintainability.

* Add `JsonDestructuringConsoleFormatter` for structured JSON logging and update logging configuration to support new formatter.

* Handling Dictionary component values with expressions

* Small improvements

* Increasing studio version

* Introduce custom activity input evaluators and support evaluator type registration. (#6889)

* Introduce custom activity input evaluators and support evaluator type registration.

Added `DefaultActivityInputEvaluator` and `DictionaryValueEvaluator` for custom input evaluation logic. Modified `InputAttribute` and `InputDescriptor` to support specifying evaluator types. Updated relevant activity, service, and feature registrations to integrate the new evaluators.

* Remove legacy Dictionary UI hint implementation and refactor `DictionaryValueEvaluator` integration.

* Removed obsolete `Dictionary` UI hint-related classes.
* Introduced `DictionaryUIHintInputModifier` for centralized modifier logic.
* Relocated `DictionaryValueEvaluator` to the appropriate namespace and updated feature registrations.

* Fix formatting of `Category` property in `Log` activity.

* Refactor input evaluation: replace `ActivatorUtilities` with `GetRequiredService` and update `DictionaryValueEvaluator` to handle dynamic types.

* Remove unused logging-related imports from `Program.cs`.

* Update src/modules/Elsa.Workflows.Core/UIHints/Dictionary/DictionaryValueEvaluator.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Add logging to `DictionaryValueEvaluator` for missing property warnings.

---------

Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
Co-authored-by: lukhipolito-nexxbiz <lucas.hipolito@nexxbiz.io>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-09-04 10:57:48 +02:00
Sipke Schoorstra 8645493b04
Introduces modular logging framework (#6872)
* Initial implementation of log activity + base sink

* Refactor logging implementation: replace `Elsa.ProcessLogging` with a new modular `Elsa.Logging` framework, introducing support for configurable log sinks, enhanced logging extensibility, and updated dependencies in consuming projects.

* Enhance logging framework: introduce custom `NullableBoolConverter` and update JSON serialization/deserialization logic for log sink handling.

* Update description for `Log` activity input: clarify target sinks configuration

* Set default value of `SinkNames` input in `Log` activity to non-nullable collection

* Set `DisplayName` for `Sinks` input in `Log` activity

* Refactor logging framework: update `ILogSink` and `ILogSinkRouter` to support arguments and attributes, enhance `Log` activity to use updated interfaces, and add default category handling.

* Refactor logging framework: simplify argument handling in `ILogSink` and `ILogSinkRouter`, update `Log` activity inputs, and improve message formatting in `MelLogSink`.

* Update logging framework to simplify log sink creation, enhance category filtering, and refactor `ILogSink`/`ILogSinkRouter` interface methods.

* Introduce modular logging framework enhancements: add `Console` and `Serilog` logging features, refactor `ILogSink` framework, and update projects to align with a modular architecture.

* Refactor logging framework: introduce `AddCategoryFilters` extension, replace `DefaultCategory` handling with enhanced category filters, and update sink creation logic for consistency.

* Refactor logging framework: rename `SinkOptions` to `LogSinkOptions`, standardize naming across log sink types, and update configuration and sink factory logic for consistency.

* Enhance logging framework: add `ConfigureDefaults` methods, update `ILogSinkCatalog` to use `IServiceScopeFactory`, and improve logging configuration handling and defaults setup.

* Introduce asynchronous log entry processing: add `ILogEntryQueue`, `LogEntryBackgroundWorker`, and related models to enable queue-based logging and background processing. Update `Log` activity to enqueue log entries for processing.

* Add unit and integration tests for `Elsa.Logging.Core` library, refactor logger setup in `Elsa.Server.Web`, enhance logging configuration, and standardize `Directory.Packages.props` file.

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Add documentation comments to logging framework classes, interfaces, methods, and factories to enhance code readability and maintainability. Remove unused `CustomPurpleConsoleFormatter` class and `logs` folder from server project.

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Make `LogEntryInstruction` and `LogEntryQueue` classes public and simplify return statement in `LogSinkCatalog.ListAsync` method.

* Standardize terminology in `ILogSink` interface and `LoggerSink` implementation: rename `properties` to `attributes`. Update project files and solution structure to reflect integration test additions.

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update documentation comments in `LoggingFeature` and `LogEntryInstruction` to clarify functionality and improve precision.

* Add README for `Elsa.Logging` module with configuration examples, usage details, and extension guidance.

* Add `Dictionary` UI hint to `InputUIHints` and update `Attributes` in `Log` activity to use it.

* Update `Log` activity default category to "Process", add integration tests for logging, and enhance null safety in `ConfigurationLogSinkProvider`.

* Remove `UseLoggingFramework` middleware from `Program.cs` to streamline workflow initialization.

---------

Co-authored-by: lucas.hipolito <lukhipolito@yahoo.com.br>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-08-25 09:55:27 +02:00
Sipke Schoorstra 0811a4042d
Merge remote-tracking branch 'origin/patch/3.4.1' into develop/3.5.0 2025-06-13 19:04:29 +02:00
Sipke Schoorstra c694a18c13
Enhances Mediator with Tenant Context Propagation (#6738)
* Update package versions in Directory.Packages.props

Upgraded multiple package dependencies to latest versions, ensuring compatibility, security, and access to the newest features.

* Refactor mediator pipeline to support tenant context propagation

- Introduced `TenantPropagatingMiddleware` to handle tenant context propagation during command execution.
- Added `SetupMediatorPipelines` hosted service for configuring mediator pipelines.
- Enhanced `CommandPipeline` and builder to allow middleware insertion, removal, and reordering.
- Updated `CommandContext` and related components to support headers for tenant context handling.
- Improved logging and refactored `BackgroundWorkflowDispatcher` to include tenant headers during command dispatch.

* Fix typos in XML documentation and improve middleware extension clarity

- Corrected duplicated slashes in XML doc comments in `ICommandSender.cs`.
- Refined phrasing in `MiddlewareExtensions.cs` to clarify method parameters and improve readability.

* Update src/common/Elsa.Mediator/Middleware/Command/Components/CommandLoggingMiddleware.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-06-13 14:26:51 +02:00
Sipke Schoorstra 8fb797eaeb
Remove Elsa.Expressions.Dsl module and related DSL features
This commit completely removes the Elsa.Expressions.Dsl module, including all associated features, services, models, and dependencies. The DSL functionality, including its custom activities and integration options, has been fully eliminated from the project.
2025-06-02 21:52:10 +02:00
Sipke Schoorstra 1f2353cad8
Remove obsolete modules and associated code
Eliminated the `Elsa.Labels`, `Elsa.Environments`, and `Elsa.OpenTelemetry` modules along with their handlers, contracts, models, and related functionality. This cleanup improves maintainability and aligns the codebase with recent architectural changes.
2025-06-02 20:05:10 +02:00
Sipke Schoorstra ddda9639ca
Merge remote-tracking branch 'origin/develop/3.5.0' 2025-06-01 18:19:32 +02:00
Sipke Schoorstra 892099c235 Refactor UI handler hierarchy and remove sample workflows.
Replaced direct implementation of `IPropertyUIHandler` with a new `PropertyUIHandlerBase` abstract class to simplify UI handler management and introduce a priority mechanism. Removed outdated `SampleWorkflow` and `SlowActivity` code to clean up the repository. Introduced a custom checklist options provider and registered it within the application services.
2025-05-26 20:06:39 +02:00
Matt 10348c5ea3 Update all dependencies to new projects. 2025-05-21 00:20:13 +01:00
Sipke Schoorstra 45f79c3ffe
Remove unused imports from Program.cs
This commit cleans up Program.cs by removing several unused using directives. The removal helps improve code readability and eliminates unnecessary references, ensuring a leaner and more maintainable codebase.
2025-05-12 14:24:50 +02:00
Sipke Schoorstra 25e36c3467
Remove unused activities, messages, and dependencies
Deleted unused custom activity classes, message types, and related registrations from the codebase. Also cleaned up surplus library references and configurations from Program.cs to streamline and simplify the project.
2025-05-12 14:13:01 +02:00
Sipke Schoorstra bbce6b6747
Merge branch 'develop/3.5.0' 2025-05-12 11:39:50 +02:00
Sipke Schoorstra 9aa239719d
Add IResilienceStrategy Abstraction with Category Matching and Expression-Based Configuration (#6637)
* Add resilience module with core interfaces and services

Introduced a new `Elsa.Resilience` module and its core components to support resilient services and activities. This includes resilience strategies, providers, and attributes, along with integration into the existing HTTP module for enhanced fault tolerance. Added solution and project references for proper dependency management.

* Add resilience strategy framework with HTTP strategy support

Introduced a resilience strategy architecture, including a configurable `HttpResilienceStrategy` with retry capabilities, strategy serialization, and integration with existing modules. Enhanced ResilienceFeature to support registration of strategy types and updated application configuration to enable resilience strategies. This change ensures more robust and fault-tolerant HTTP request handling.

* Add JSON serialization support for resilience configuration

Introduced `ConfigurationExtensions` to enable JSON serialization of configuration sections. Updated resilience strategies to utilize the new extension methods and adjusted JSON serialization logic to support polymorphism with `$type` discriminator. Minor modifications were made to support deserialization and property mutability.

* Add resilience strategy support to workflows and API clients

Introduced resilience strategy configuration, serialization, and execution support across workflows and API clients. Added new APIs, models, and services to enhance fault tolerance capabilities for activities and HTTP interactions.

* Refactor resilience services for improved modularity.

Replaced `IResilienceService` with new modular interfaces (`IResilienceStrategyCatalog`, `IResilienceStrategyConfigEvaluator`, `IResilientActivityInvoker`) and corresponding implementations. Enhanced maintainability by simplifying components and responsibilities, ensuring better separation of concerns.

* Rename methods in ResilienceStrategyCatalog for clarity

Updated method names in `ResilienceStrategyCatalog` and its interfaces for better readability and alignment with naming conventions. Replaced `GetAllStrategiesAsync` with `ListAsync` and `GetStrategyAsync` with `GetAsync` across the codebase.

* Refactor resilience handling in HTTP activities.

Replaced `ResilienceCategory` property with `ResilienceCategoryAttribute` for a cleaner implementation. Updated `IResilientActivity` to simplify its interface and adjusted related modifications accordingly. Introduced `IResilientActivityInvoker` to enhance resilience strategy execution.

* Add support for additional resilience and scripting features

Extended resilience strategy handling with serialization support, added `HttpResilienceStrategy` type in JavaScript handler, and refined object conversion logic for interfaces. Minor adjustments to `Expression` class properties for consistency.

* Remove `UseResilience` call from Program.cs

This call was redundant and no longer necessary for the application. Its removal simplifies the code and ensures only required middleware is used.

* Remove commented-out JSON converter code in serializer setup

Cleaned up unused and commented-out converter initialization code in `ResilienceStrategySerializer`. This improves readability and removes unnecessary clutter from the file.

* Fix typo in method names from 'Resiliency' to 'Resilience'

Renamed methods to maintain consistency in naming conventions across the codebase. This change ensures clarity and alignment with established terminology.

* Refactor namespace for ConfigurationResilienceStrategySource

Updated the namespace of ConfigurationResilienceStrategySource to "StrategySources" for better alignment with naming conventions and structure. Removed an unused namespace reference in ResilienceFeature for cleanup.

* Mark EnableResiliency as obsolete in SendHttpRequestBase.

The EnableResiliency property is now marked with the [Obsolete] attribute. Developers are encouraged to use the common Resilience Strategy setting instead for managing HTTP request resiliency. This change ensures better consistency and alignment with the broader resilience strategy.

* Restrict ResilienceCategoryAttribute to class targets only

Removed support for using ResilienceCategoryAttribute on properties. This change enforces a stricter and more focused usage of the attribute, ensuring it applies only to class-level declarations.

* Add documentation for IResilientActivityInvoker interface

Include summaries and parameter descriptions for the `InvokeAsync` method. This improves code clarity and helps developers understand the functionality and usage of the resilient activity invocation process.

* Fix logical operator precedence in type comparison check

Parentheses were added to ensure correct evaluation of conditions when checking type compatibility. This prevents potential logical errors when determining the target type in object conversions.

* Add support for resilience source identification

Introduce the `ResilienceSourceNameAttribute` to allow naming of resilience sources. Updated `ResilienceStrategyCatalog` to utilize the attribute for prefixing strategy IDs, improving source identification and traceability. Applied the attribute to `ConfigurationResilienceStrategySource` as an example.

* Revert "Add support for resilience source identification"

This reverts commit 19b4e7121d6330b5de4f692b78da4c1e4a2d1f67.

* Reapply "Add support for resilience source identification"

This reverts commit 8bcba9d040c4eb247077aec6d90dc02817adcbd5.

* Revert "Reapply "Add support for resilience source identification""

This reverts commit ee04d35e7930956c752dda3ed150ca34a535e66c.
2025-05-12 10:09:04 +02:00
Matt cfef5acdac
Remove Sql Activities from Core to the new Integrations Repo. (#6625) 2025-05-09 19:53:31 +02:00
Sipke Schoorstra f0639cbd42
Refactor OpenTelemetry error handling implementation (#6621)
* Refactor OpenTelemetry error handling implementation

Introduce WorkflowErrorSpanHandler interface and context for improved error span handling in workflows. Separate activity and workflow error handling using dedicated abstractions and context models. Update error handling logic in tracing middleware and adjust DI configuration accordingly.

* Rename handler class and improve error tagging logic

Renamed `FaultExceptionActivityErrorSpanHandler` to `FaultExceptionErrorSpanHandler` for consistency and clarity. Updated error attribute tagging to align with Datadog's well-known attributes. Adjusted incident selection logic to use the first incident instead of the last.

* Align .gitignore file with consistent formatting

Standardized comments in the .gitignore file by adding missing spaces and capitalizing as needed. Updated the `/docker/data/` entry to `/docker/azurite-data/` for clarity.

* Fix incorrect selection of activity execution context

Replaced `LastOrDefault` with `FirstOrDefault` to ensure the correct activity execution context is retrieved when handling errors. This change resolves potential inaccuracies in identifying the faulted activity node.

* Exclude docker-compose-datadog.yml from solution file.
2025-05-07 10:59:44 +02:00
Sipke Schoorstra 2eec542f50
Merge remote-tracking branch 'origin/rc/3.4.0' 2025-04-16 08:41:04 +02:00
Sipke Schoorstra 8c52acece5
Fix MessageReceived not setting Result (#6562)
* Fix MessageReceived not setting Result

Fixes #6540

* Add custom equality comparer for VariableDescriptor

Introduced a `VariableDescriptorComparer` to ensure proper equality checks within `HashSet<VariableDescriptor>`. Updated related code to use the comparer and added a new message type `OrderReceived` for MassTransit integration.
2025-04-10 15:02:39 +02:00
Sipke Schoorstra e2288d0b34
Fix infinitely waiting Alterations Workflow (#6561)
* Refactor TenantId string handling and nullability checks.

Moved `StringExtensions` to a common module for reuse. Updated tenant-related logic to utilize null-safe string extensions, enhancing consistency and simplifying nullability handling across the codebase.

* Set StrictMode to false by default in ObjectConverter

Modified the default value of StrictMode to `false` to enable the original flexible behavior. Developers can opt into strict mode by explicitly setting it to `true`. This change aims to enhance backward compatibility and minimize unexpected strict conversions.

* Add tenant ID retrieval to ElsaDbContextBase constructor

Retrieve the current tenant ID if available using ITenantAccessor and assign it to the TenantId property. This ensures proper handling of multi-tenancy scenarios in the database context initialization.

* Disable DbContext pooling, manual OTEL instrumentation, and strict mode.

DbContext pooling is turned off to prevent potential issues with shared context instances. Manual OpenTelemetry instrumentation is disabled to rely on automatic instrumentation instead. Strict mode is also disabled to allow more flexibility in object conversion.

* Fix infinitely waiting Alterations Workflow

Replaced workflow dispatch logic with BookmarkQueue and StimulusHasher for triggering workflows. This fixes the issue where the Alterations workflow would signal completion while a later step awaits a completion bookmark. The Bookmark Queue now handles this.
2025-04-05 10:37:05 +02:00
Raymond den Haan d4b0238501 Moved compression to separate feature 2025-04-03 15:40:17 +02:00
Sipke Schoorstra fb1feb5ac4
Merge branch 'rc/3.4.0' 2025-04-01 10:23:04 +02:00
Sipke Schoorstra 952cbb4edc
Add strict type checking for variable parsing (#6536)
* Add strict type checking for variable parsing

Introduced a `StrictMode` flag for variables, enforcing stricter type validation during parsing and conversions. Updated related methods and tests to reflect the stricter parsing behavior, ensuring consistent type compatibility and error handling.

* Refactor StrictMode handling and improve ObjectConverter logic

Moved StrictMode flag from Variable to ObjectConverter for better cohesion and updated related references. Additionally, removed unused parameters and simplified ObjectConverterOptions to streamline configuration and maintain consistency across the codebase.

* Refactor type conversion logic and update logging defaults

Improve type conversion reliability by introducing `TryConvertValue` and refining exception handling. Update JSON scenarios to use "Inherit" as the default for log persistence modes, ensuring consistency across configurations.

* Refactor exception handling in ObjectConverter.

Introduce a helper method `ReturnOrThrow` to streamline and centralize exception handling logic. This change also adds support for non-strict mode, allowing value fallback instead of throwing exceptions when enabled.

* Add numeric type checks and improve type conversion handling

Introduce `IsNumericType` extension method to identify numeric types. Enhance type conversion logic in `ObjectConverter` to handle numeric, boolean, and string types more accurately. Update variable deserialization workflows to handle conversion failures gracefully.

* Set a default comment for ObjectConverter.StrictMode assignment

Added a comment clarifying that StrictMode is set to its default value. This improves code readability and helps maintainers understand the intent.

* Fix formatting inconsistencies and improve code clarity

Removed redundant whitespace and adjusted formatting to align with coding standards. These changes enhance the readability and maintainability of the code without altering functionality.

* Fix typo in Program.cs variable comment

Corrected a minor issue in the comment for `identityTokenSection` to remove the unnecessary "Modify" text. This change improves code readability and removes potential confusion for developers.

* Simplify imports in ModifyVariableHandler.cs

Removed unused `Microsoft.Extensions.Options` and `Elsa.Workflows.Options` imports to clean up dependencies and improve maintainability. This change reduces clutter without affecting the existing functionality.
2025-03-31 18:11:14 +02:00
Sipke Schoorstra 06b9907d85
Fix DbContext pooling (#6531)
* Enable DbContext pooling and refactor DI scopes

Added support for using DbContext pooling with a configurable option. Refactored to use scoped service providers for better isolation and lifecycle management. Updated persistence feature base to integrate sensitive data logging and warning configurations.

* Update package management and Elsa Studio version references

Centralized package versioning remains enabled, while unused package references and conditional groups for specific .NET targets are removed for simplification. Elsa Studio version is upgraded from 3.3.0-rc4 to 3.4.0-rc1.

* Simplify DbContextOptions setup logic

Removed conditional compilation and unused code to streamline the DbContextOptions configuration. This improves maintainability and ensures consistent behavior across frameworks. Sensitive data logging is no longer explicitly enabled here.
2025-03-26 16:05:40 +01:00
Sipke Schoorstra 51dff1a061
Support for Writing Custom Trigger Activities Using Existing Trigger Infrastructure (#6527)
* Refactor bookmark naming to use "Name" instead of "ActivityTypeName".

Replaces usages of "ActivityTypeName" with "Name" across relevant classes, filters, and database mappings for clarity and consistency. Maintains backward compatibility where necessary and updates corresponding indices, filters, and methods for proper functionality.

* Add migration for V3_5 with schema updates for EF Core

This migration modifies the `Triggers` and `Bookmarks` tables by adding the `Name` column, updating its nullable state, and creating corresponding indexes. Changes apply to both SQLite and MySQL contexts, ensuring compatibility across databases.

* Refactor bookmark filtering and tenant events handling.

Unified the bookmark filtering logic with overloads that accept multiple names, improving flexibility and reusability. Simplified object initializations in tenant events to enhance code readability and reduce verbosity. Added task continuation logic to background task execution for better task sequencing and error handling.

* Refactor bookmark creation to use target-typed `new` expressions.

Replaces explicit `CreateBookmarkArgs` instantiations with concise target-typed `new` expressions for improved readability and reduced redundancy. This does not alter functionality but simplifies the code structure.

* Make callback parameters optional and adjust OTEL settings

Updated methods to allow optional callbacks for improved flexibility. Refactored Delay activity to reuse helper methods. Adjusted OTEL instrumentation settings to enable console exporter and disable manual instrumentation.

* Refactor stimulus handling and streamline event workflows.

Introduces `WaitForEvent` and `GetEventInput` extensions to improve ActivityExecutionContext usability. Replaces generic filter methods with targeted single-name filtering, simplifying scheduling logic. Updates stimulus names for consistency and deprecates obsolete methods to enhance clarity and maintainability.

* Refactor `Event` activity handling and event stimulus logic.

Replaces inline event stimulus creation with a new `GetEventStimulus` helper method for cleaner code. Simplifies event execution handling by removing redundant logic in `ExecuteAsync`. Extends `WaitForEvent` to handle workflow triggers more efficiently.

* Refactor and enhance Timer and Delay execution logic

Introduced `TimerBase` for shared timer functionality and refactored `Timer` to extend it. Improved method names for clarity, replacing `ResumeIn`/`ResumeAt` with `DelayFor`/`DelayUntil`. Enhanced flexibility in bookmark handling and activity execution context extensions.

* Add custom activities and refactor HTTP stimulus handling

Introduce new custom activities (CustomDelay, CustomEvent, CustomHttpEndpoint, CustomTimer) to enhance workflow functionality. Refactor HTTP stimulus handling by replacing activity type names with a new centralized HttpStimulusNames constant, improving consistency and maintainability. Additionally, streamline HTTP endpoint logic with new helper extensions and simplify related services to reduce redundancy.

* Add HttpEndpointBase abstraction to simplify HTTP endpoints

Introduce a new `HttpEndpointBase` class to centralize common logic for HTTP endpoint activities. Refactored `CustomHttpEndpoint` to inherit from this new base class, reducing redundancy and improving maintainability.

* Refactor events framework with base class for event activities

Introduce `EventBase` to streamline implementations of event-driven activities. Updated `CustomEvent` to inherit from `EventBase`, reducing duplicate logic and improving maintainability. Removed unnecessary dependencies in `CustomTimer`.

* Refactor bookmark creation to use target-typed `new` expressions.

Replaces explicit `CreateBookmarkArgs` instantiations with concise target-typed `new` expressions for improved readability and reduced redundancy. This does not alter functionality but simplifies the code structure.

Make callback parameters optional and adjust OTEL settings

Updated methods to allow optional callbacks for improved flexibility. Refactored Delay activity to reuse helper methods. Adjusted OTEL instrumentation settings to enable console exporter and disable manual instrumentation.

Refactor stimulus handling and streamline event workflows.

Introduces `WaitForEvent` and `GetEventInput` extensions to improve ActivityExecutionContext usability. Replaces generic filter methods with targeted single-name filtering, simplifying scheduling logic. Updates stimulus names for consistency and deprecates obsolete methods to enhance clarity and maintainability.

Refactor `Event` activity handling and event stimulus logic.

Replaces inline event stimulus creation with a new `GetEventStimulus` helper method for cleaner code. Simplifies event execution handling by removing redundant logic in `ExecuteAsync`. Extends `WaitForEvent` to handle workflow triggers more efficiently.

Refactor and enhance Timer and Delay execution logic

Introduced `TimerBase` for shared timer functionality and refactored `Timer` to extend it. Improved method names for clarity, replacing `ResumeIn`/`ResumeAt` with `DelayFor`/`DelayUntil`. Enhanced flexibility in bookmark handling and activity execution context extensions.

Add custom activities and refactor HTTP stimulus handling

Introduce new custom activities (CustomDelay, CustomEvent, CustomHttpEndpoint, CustomTimer) to enhance workflow functionality. Refactor HTTP stimulus handling by replacing activity type names with a new centralized HttpStimulusNames constant, improving consistency and maintainability. Additionally, streamline HTTP endpoint logic with new helper extensions and simplify related services to reduce redundancy.

Add HttpEndpointBase abstraction to simplify HTTP endpoints

Introduce a new `HttpEndpointBase` class to centralize common logic for HTTP endpoint activities. Refactored `CustomHttpEndpoint` to inherit from this new base class, reducing redundancy and improving maintainability.

Refactor events framework with base class for event activities

Introduce `EventBase` to streamline implementations of event-driven activities. Updated `CustomEvent` to inherit from `EventBase`, reducing duplicate logic and improving maintainability. Removed unnecessary dependencies in `CustomTimer`.

* Move HttpEndpointOptions model to its own file

The HttpEndpointOptions class was moved from an extension file to its own dedicated file for better organization and modularity. This model defines HTTP endpoint properties such as path, methods, authorization, policies, request timeout, and size limit. The change improves code clarity and structure.

* Fix unnecessary whitespace in Timer.cs

Removed an extra whitespace line in the Timer.cs file to maintain code formatting consistency. No functional changes were made to the code.

* Remove extraneous whitespace in IStimulusSender.cs file

Eliminate unnecessary blank line in the IStimulusSender interface for improved code cleanliness. This change enhances readability and aligns with coding standards.
2025-03-21 23:16:56 +01:00
Sipke Schoorstra 735a513790
Merge branch 'main' into enh/otel 2025-03-16 22:36:25 +01:00
Sipke Schoorstra 39932a6f09
Refactor OpenTelemetry tracing and improve span tagging.
Introduced new span tags for activities and workflows to enhance trace analysis. Optimized error handling in activity tracing by selecting the first applicable handler. Removed unused manual tracing configuration and commented out console exporters in server setup.
2025-03-14 23:55:02 +01:00
Sipke Schoorstra fd31b5b605
Update OTEL fields and tags
Added and updated multiple package references, including OpenTelemetry, Datadog.Trace.Bundle, and various Microsoft.Extensions libraries. This ensures compatibility with the latest dependencies and introduces enhanced features for resilience and tracing.
2025-03-14 23:17:54 +01:00
Sipke Schoorstra 094291b673
Merge branch 'main' into enh/workflowinstance-name 2025-03-14 23:03:33 +01:00
Sipke Schoorstra 414d18ee80
Refactor YugabyteDB connection configuration.
Removed unnecessary `With()` method in `UsePostgreSql` for YugabyteDB. This simplifies the configuration and ensures consistency across database providers.
2025-03-11 14:23:18 +01:00