elsa-workflows / elsa-core

A .NET workflows library
https://v3.elsaworkflows.io/
MIT License
6.27k stars 1.15k forks source link

[FEAT] Real-time Workflow Definition Refresh and Update via Refresh API Endpoint #5688

Closed sfmskywalker closed 2 months ago

sfmskywalker commented 3 months ago

Summary

Implement a new API endpoint to refresh workflow definitions in real-time, either for all definitions or a specified list of IDs.

Endpoint Details

Permissions Required

Internal Operations

Additional Update

Objective

Enhance the system's ability to dynamically refresh workflow definitions to ensure they are up-to-date without requiring a full system restart or manual intervention.

glime-ai[bot] commented 3 months ago

To implement a new API endpoint to refresh workflow definitions in real-time, you would need to follow these steps:

  1. Define the Endpoint Route and Method: Create a new controller or extend an existing one with a method to handle the POST request to /actions/workflow-definitions/refresh.

  2. Request Body Parsing: Parse the incoming request body to extract the WorkflowDefinitionIds array. If the array is empty or undefined, the operation should refresh all workflow definitions.

  3. Permission Check: Ensure that the caller has the required permission (actions:workflow-definitions:refresh) to perform this action.

  4. Service Injection: Inject the IWorkflowDefinitionStore service to access workflow definitions and the ITriggerIndexer service to re-index triggers.

  5. Fetching Workflow Definitions: Use the IWorkflowDefinitionStore service to fetch the workflow definitions that need to be refreshed. If WorkflowDefinitionIds is provided, fetch those specific definitions; otherwise, fetch all published workflow definitions.

  6. Batch Processing: To avoid memory overload, process the workflow definitions in batches. For each batch, perform the following steps:

    • Re-indexing Triggers: Use the ITriggerIndexer service to re-index the triggers for each workflow definition in the batch.

    • Evict Cache (if applicable): If the system uses a cache for workflow definitions, ensure that the cache is evicted for the updated definitions.

  7. Response: Once all the workflow definitions have been processed, return a success response to the caller.

  8. Evict Workflow Definition Service Cache: Update the EvictWorkflowDefinitionServiceCache handler to listen for the WorkflowTriggersIndexed notification and evict the workflow definition service cache accordingly.

  9. Testing: Write unit tests and integration tests to verify that the endpoint behaves as expected, including permission checks, request body parsing, batch processing, and cache eviction.

  10. Documentation: Update the API documentation to include the new endpoint, its usage, request/response formats, and any relevant examples.

Please note that the actual implementation would require writing code in the programming language and framework used by the system, which typically involves creating controllers, services, and other components as needed.

This comment was generated by Glime.

sfmskywalker commented 2 months ago

Done via https://github.com/elsa-workflows/elsa-core/pull/5713