Skip to content

Conversation

@p14n
Copy link
Owner

@p14n p14n commented Jun 21, 2025

Summary by Sourcery

Add support for fetching and processing the single latest message in CatchupService, wired through a new SystemEvent.FetchLatest, backed by server- and gRPC-side getLatestMessageId, with accompanying tests and build publishing setup

New Features:

  • Implement fetchLatest in CatchupService to process the newest event beyond the current high-water mark and persist it
  • Introduce SystemEvent.FetchLatest and SystemEventBroker.triggerFetchLatest to initiate fetch-latest workflows
  • Extend CatchupServerInterface, CatchupServer, CatchupGrpcClient, and CatchupGrpcServer with getLatestMessageId to retrieve the highest message ID for a topic

Build:

  • Add gradle.properties with Maven Central credentials and signing configuration for artifact publishing

Tests:

  • Add CatchupServiceTest methods to verify fetchLatest behavior with and without new messages

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jun 21, 2025

Reviewer's Guide

This PR introduces a fetchLatest feature that compares the current high‐water mark against the latest server message ID, fetches and persists one new event if available, extends the catchup server and gRPC layers to expose latest‐ID lookup, adds a system event path to trigger fetchLatest, and includes unit tests covering both new‐message and no‐newer‐message scenarios.

Sequence diagram for fetchLatest event processing

sequenceDiagram
    participant SystemEventBroker
    participant CatchupService
    participant CatchupServer
    participant Database

    SystemEventBroker->>CatchupService: Publish SystemEvent.FetchLatest
    CatchupService->>CatchupServer: getLatestMessageId(topic)
    CatchupServer->>Database: SELECT MAX(idn) FROM postevent.{topic}
    Database-->>CatchupServer: latestId
    CatchupServer-->>CatchupService: latestId
    CatchupService->>CatchupServer: fetchEvents(latestId-1, latestId, 1, topic)
    CatchupServer-->>CatchupService: List<Event>
    CatchupService->>Database: writeEventsToMessagesTable(events)
    CatchupService->>SystemEventBroker: Publish SystemEvent.CatchupRequired (if event processed)
    CatchupService-->>SystemEventBroker: Return processedCount
Loading

Class diagram for CatchupServerInterface and implementations with fetchLatest support

classDiagram
    class CatchupServerInterface {
        +List<Event> fetchEvents(long, long, int, String)
        +long getLatestMessageId(String)
    }
    class CatchupServer {
        +List<Event> fetchEvents(...)
        +long getLatestMessageId(String)
    }
    class CatchupGrpcClient {
        +List<Event> fetchEvents(...)
        +long getLatestMessageId(String)
    }
    class CatchupGrpcServer {
        +void getLatestMessageId(GetLatestMessageIdRequest, StreamObserver)
    }
    CatchupServerInterface <|.. CatchupServer
    CatchupServerInterface <|.. CatchupGrpcClient
    CatchupGrpcServer --> CatchupServer : uses

    class CatchupService {
        +int fetchLatest(String)
        +void onMessage(SystemEvent)
    }
    class SystemEventBroker {
        +void triggerFetchLatest(String)
    }
    class SystemEvent {
        CatchupRequired
        UnprocessedCheckRequired
        FetchLatest
        String topic
    }
Loading

Class diagram for SystemEvent and SystemEventBroker changes

classDiagram
    class SystemEvent {
        <<enum>>
        CatchupRequired
        UnprocessedCheckRequired
        FetchLatest
        String topic
    }
    class SystemEventBroker {
        +void triggerFetchLatest(String)
    }
Loading

File-Level Changes

Change Details Files
Introduce fetchLatest method in CatchupService
  • Retrieve current HWM from the database
  • Invoke catchupServer.getLatestMessageId to get the latest ID
  • Fetch and write the single new event when ID > HWM, commit, and publish CatchupRequired
  • Extend onMessage to handle SystemEvent.FetchLatest
CatchupService.java
Extend CatchupServer and gRPC layers to support latest‐ID retrieval
  • Add getLatestMessageId to CatchupServerInterface
  • Implement MAX(idn) query in CatchupServer
  • Expose getLatestMessageId RPC in CatchupGrpcServer
  • Invoke gRPC stub in CatchupGrpcClient.getLatestMessageId
CatchupServerInterface.java
CatchupServer.java
CatchupGrpcServer.java
CatchupGrpcClient.java
Add system‐event trigger for fetchLatest
  • Add FetchLatest enum value in SystemEvent
  • Add triggerFetchLatest helper in SystemEventBroker
SystemEvent.java
SystemEventBroker.java
Add unit tests for fetchLatest behavior
  • Test branch with a newer message (processes one event)
  • Test branch with no newer message (processes zero)
  • Add getMaxIdnFromMessagesTable helper to verify DB state
CatchupServiceTest.java
Update build properties with publishing credentials
  • Add Maven Central username/password
  • Configure signing key ID and password
gradle.properties

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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