Skip to content

feat: add batch support - #18

Merged
yordis merged 4 commits into
mainfrom
sync-trunk-1
Jun 25, 2025
Merged

yordis merged 4 commits into
mainfrom
sync-trunk-1

Conversation

@yordis

@yordis yordis commented Jun 25, 2025

Copy link
Copy Markdown
Member

No description provided.

@coderabbitai

coderabbitai Bot commented Jun 25, 2025 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

Walkthrough

Batch event processing support was added to the Commanded event handler infrastructure, introducing the handle_batch/1 callback, batch-specific telemetry, and error handling. Configuration options enforce mutual exclusivity between concurrency and batch size. Extensive tests and supporting modules were added to validate batch processing, state management, telemetry, error handling, and handler reset logic.

Changes

File(s) / Module(s) Change Summary
lib/commanded/event/handler.ex Added batch processing: handle_batch/1 callback, batch telemetry, error handling, config validation, and documentation.
lib/commanded/event_store/adapter.ex Enhanced documentation for ack_event/3 to clarify batch acknowledgment semantics.
lib/commanded/event_store/adapters/in_memory.ex Added debug logging for event acknowledgment in ack_persistent_subscription_by_pid/3.
test/event/event_handler_batch_state_test.exs,
test/event/support/state/stateful_batched_event_handler.ex
Added stateful batch handler and tests for state management and batch processing.
test/event/event_handler_batch_subscribe_to_stream_test.exs Added test and handler for subscribing to a single stream with batch processing.
test/event/event_handler_batch_telemetry_test.exs Added tests for batch handler telemetry events (start, stop, exception) under various scenarios.
test/event/event_handler_batch_test.exs,
test/event/support/batch_handler.ex,
test/event/support/error_handling_batch_handler.ex
Added batch handler, error handling batch handler, and tests for batch processing and error strategies.
test/event/event_handler_macro_test.exs,
test/event/handler_config_test.exs
Added tests for config validation: mutual exclusivity of concurrency and batch_size, and compile-time callback checks.
test/event/event_handler_state_test.exs Ensured handler process termination after each stateful event handler test.
test/event/reset_batch_event_handler_test.exs,
test/example_domain/bank_account/bank_account_batch_handler.ex
Added batch handler and tests for handler reset and batch state management in a banking domain scenario.
test/event/support/upcast/batch_event_handler.ex,
test/event/upcaster_test.exs
Added batch upcast handler and tests for upcasted event batch processing.
test/event_store/adapters/in_memory/in_memory_test.exs Added test for single event acknowledgment in the in-memory event store.

Sequence Diagram(s)

sequenceDiagram
    participant EventStore
    participant EventHandler
    participant UserApp

    UserApp->>EventStore: Append batch of events
    EventStore->>EventHandler: Send {:events, events} message
    alt Batch processing enabled
        EventHandler->>EventHandler: handle_batch(events)
        EventHandler->>UserApp: Send batch result/notification
        EventHandler->>EventStore: ack_event for last event in batch
    else Single event processing
        loop For each event
            EventHandler->>EventHandler: handle(event, metadata)
            EventHandler->>UserApp: Send event result/notification
            EventHandler->>EventStore: ack_event for event
        end
    end
Loading

Poem

In the warren, events now hop in a pack,
Batching together, they bound down the track.
Telemetry sings as the handler delights,
With errors and retries on long bunny nights.
No more lone carrots—now bunches are chewed,
Batch logic is here, and the code’s feeling renewed!
🥕🥕🥕


📜 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 31337cb and 2607718.

📒 Files selected for processing (18)
  • lib/commanded/event/handler.ex (24 hunks)
  • lib/commanded/event_store/adapter.ex (1 hunks)
  • lib/commanded/event_store/adapters/in_memory.ex (2 hunks)
  • test/event/event_handler_batch_state_test.exs (1 hunks)
  • test/event/event_handler_batch_subscribe_to_stream_test.exs (1 hunks)
  • test/event/event_handler_batch_telemetry_test.exs (1 hunks)
  • test/event/event_handler_batch_test.exs (1 hunks)
  • test/event/event_handler_macro_test.exs (1 hunks)
  • test/event/event_handler_state_test.exs (5 hunks)
  • test/event/handler_config_test.exs (1 hunks)
  • test/event/reset_batch_event_handler_test.exs (1 hunks)
  • test/event/support/batch_handler.ex (1 hunks)
  • test/event/support/error_handling_batch_handler.ex (1 hunks)
  • test/event/support/state/stateful_batched_event_handler.ex (1 hunks)
  • test/event/support/upcast/batch_event_handler.ex (1 hunks)
  • test/event/upcaster_test.exs (1 hunks)
  • test/event_store/adapters/in_memory/in_memory_test.exs (2 hunks)
  • test/example_domain/bank_account/bank_account_batch_handler.ex (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.

@yordis
yordis marked this pull request as ready for review June 25, 2025 19:10
@yordis
yordis merged commit b593f04 into main Jun 25, 2025
@yordis
yordis deleted the sync-trunk-1 branch June 25, 2025 19:10
@coderabbitai coderabbitai Bot mentioned this pull request Oct 28, 2025
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.

2 participants