Skip to content

feat(workflow): add workflow data update methods and caching #855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2025

Conversation

pcfreak30
Copy link
Member

@pcfreak30 pcfreak30 commented Jul 6, 2025

  • Added UpdateWorkflowData and UpdateWorkflowDataStruct methods to OperationHelper
  • Cached WorkflowService instance in OperationHelperDefault
  • Added MergeStruct method to WorkflowOptions for struct merging
  • Simplified WithWorkflowStructData option using new MergeStruct
  • Improved workflow metadata handling in WorkflowCoordinator
  • Fixed metadata byte handling in workflow service

Summary by CodeRabbit

  • New Features

    • Added the ability to update workflow metadata using either a map or a struct, allowing more flexible and structured workflow data updates.
  • Refactor

    • Improved internal handling of workflow data updates for better efficiency and maintainability.
    • Enhanced merging of structured data into workflow options for streamlined configuration management.

- Added UpdateWorkflowData and UpdateWorkflowDataStruct methods to OperationHelper
- Cached WorkflowService instance in OperationHelperDefault
- Added MergeStruct method to WorkflowOptions for struct merging
- Simplified WithWorkflowStructData option using new MergeStruct
- Improved workflow metadata handling in WorkflowCoordinator
- Fixed metadata byte handling in workflow service
Copy link

coderabbitai bot commented Jul 6, 2025

Walkthrough

The changes introduce new methods to update workflow data using either maps or structs across the OperationHelper, WorkflowService, and WorkflowCoordinatorDefault interfaces and implementations. Struct merging into workflow options is now supported. Internal caching of the workflow service is added to OperationHelperDefault for efficiency.

Changes

File(s) Change Summary
core/operation.go Extended OperationHelper interface and OperationHelperDefault with UpdateWorkflowData and UpdateWorkflowDataStruct methods; added workflow service caching.
core/workflow.go Added UpdateWorkflowData, UpdateWorkflowDataStruct to WorkflowService; added MergeStruct to WorkflowOptions; implemented struct merging logic. Refactored WithWorkflowStructData to use new method.
service/workflow.go Added UpdateWorkflowData and UpdateWorkflowDataStruct to WorkflowCoordinatorDefault for updating workflow metadata in requests; renamed local variable for clarity.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant OperationHelper
    participant WorkflowService
    participant WorkflowCoordinator
    participant RequestDB

    Client->>OperationHelper: UpdateWorkflowData(requestID, data)
    OperationHelper->>WorkflowService: UpdateWorkflowData(ctx, requestID, data)
    WorkflowService->>WorkflowCoordinator: UpdateWorkflowData(ctx, requestID, data)
    WorkflowCoordinator->>RequestDB: Retrieve and update request metadata
    RequestDB-->>WorkflowCoordinator: Success/Failure
    WorkflowCoordinator-->>WorkflowService: Result
    WorkflowService-->>OperationHelper: Result
    OperationHelper-->>Client: Result
Loading
sequenceDiagram
    participant Client
    participant OperationHelper
    participant WorkflowService

    Client->>OperationHelper: UpdateWorkflowDataStruct(requestID, structData)
    OperationHelper->>WorkflowService: UpdateWorkflowDataStruct(ctx, requestID, structData, tag)
    WorkflowService->>WorkflowCoordinator: UpdateWorkflowDataStruct(ctx, requestID, structData, tag)
    WorkflowCoordinator->>RequestDB: Retrieve, merge, update metadata
    RequestDB-->>WorkflowCoordinator: Success/Failure
    WorkflowCoordinator-->>WorkflowService: Result
    WorkflowService-->>OperationHelper: Result
    OperationHelper-->>Client: Result
Loading

Possibly related PRs

Poem

A bunny with code in its paws,
Updates workflows without a pause.
Maps and structs now merge with glee,
Metadata fresh as can be!
With helpers cached and methods new,
This rabbit hops—your workflows grew!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e0323f4 and 2b35540.

📒 Files selected for processing (3)
  • core/operation.go (5 hunks)
  • core/workflow.go (4 hunks)
  • service/workflow.go (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
core/workflow.go (2)
build/build_info.go (1)
  • New (136-168)
db/provider.go (1)
  • Provider (12-19)
🔇 Additional comments (12)
core/operation.go (5)

120-123: Well-designed interface extension for workflow data updates.

The addition of both map-based (UpdateWorkflowData) and struct-based (UpdateWorkflowDataStruct) update methods provides flexible options for callers while maintaining consistency with the existing structured workflow data pattern.


141-141: Good optimization: caching workflow service instance.

Caching the workflow service in the struct eliminates repeated service lookups and improves performance for operations that make multiple workflow-related calls.


152-152: Consistent initialization of cached workflow service.

Both constructors properly initialize the cached workflow service, ensuring the optimization is available regardless of which constructor is used.

Also applies to: 162-162


235-243: Clean implementation of new update methods.

The implementation correctly delegates to the cached workflow service, passing the appropriate parameters including the unmarshal tag for struct-based updates. The error handling is properly propagated.


247-247: Consistent refactoring to use cached service.

The StartWorkflow method has been properly updated to use the cached workflow service, maintaining consistency with the new optimization pattern.

core/workflow.go (4)

56-61: Interface extension matches OperationHelper pattern.

The WorkflowService interface extension is consistent with the corresponding changes in OperationHelper, providing both map-based and struct-based update methods with clear documentation.


114-114: Logical addition to WorkflowOptions interface.

Adding MergeStruct to the WorkflowOptions interface complements the existing MergeData and MergeJSON methods, providing a complete set of data merging capabilities.


190-207: Well-implemented MergeStruct method following established patterns.

The implementation correctly:

  • Initializes koanfCache if nil (consistent with other merge methods)
  • Creates a temporary koanf instance to load struct data
  • Uses the structs.Provider with the specified tag for unmarshaling
  • Merges into the cached instance and updates raw data
  • Handles errors appropriately

This follows the same pattern as MergeJSON and maintains consistency across the codebase.


275-275: Good refactoring to eliminate code duplication.

The WithWorkflowStructData function now leverages the new MergeStruct method instead of duplicating the struct loading logic, making the code more maintainable and DRY.

service/workflow.go (3)

102-108: Minor improvement in variable naming for clarity.

The change from metadataBytes to dataBytes better reflects that this variable contains the marshaled workflow data, not the entire metadata structure. The logic remains unchanged.


644-683: Robust implementation of workflow data updates.

The UpdateWorkflowData method correctly:

  • Retrieves and validates the existing request
  • Parses the current workflow metadata
  • Merges existing workflow data with new data using WorkflowOptions
  • Handles the case where no existing data exists
  • Marshals the updated data back to the metadata structure
  • Persists the changes via the request service

The error handling is comprehensive with descriptive error messages.


685-694: Clean delegation pattern for struct-based updates.

The UpdateWorkflowDataStruct method properly:

  • Creates a new WorkflowOptions instance
  • Uses the new MergeStruct method with the provided tag
  • Delegates to UpdateWorkflowData with the resulting map data

This approach avoids code duplication while providing the struct-based interface.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@pcfreak30 pcfreak30 merged commit e129a03 into develop Jul 6, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant