Skip to content
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

WIP on python substreams handler #6

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dkdocs
Copy link

@dkdocs dkdocs commented Nov 11, 2024

PR Description: Abstracted gRPC Stream Event Processing and Enhanced Cursor Management

This PR refactors the existing gRPC streaming code to provide a reusable, abstracted event processing structure and introduces improved cursor management for efficient event handling. The following key changes and improvements have been made:


Key Changes

  1. Abstracted Event Processing with EventProcessor Interface

    • Introduced an EventProcessor abstract base class to decouple the event processing logic from the core gRPC connection and cursor handling.
    • Added a default implementation, DefaultEventProcessor, which can be replaced or extended to customize event handling.
    • This design allows easy reuse of the streaming logic with different processing behaviors by subclassing EventProcessor.
  2. Improved gRPC Connection Management

    • Encapsulated gRPC connection management in a start_stream function, making it easier to handle reconnections and manage metadata.
    • Added functionality to handle reconnections in case of RpcError, with a delay between retry attempts.
  3. Cursor Management

    • Implemented functions save_cursor_to_file and get_cursor_from_file to save and retrieve the cursor position, allowing the stream to resume from where it left off.
    • This ensures continuity in data processing, especially in long-running or live stream scenarios.

Instructions for Testing

  1. Run the Script:

    python main.py <package_url> <module_name> [start_block] [stop_block]
    • Replace <package_url> and <module_name> with the appropriate values.
    • Optional [start_block] and [stop_block] arguments specify the block range.
  2. Customize Event Processing:

    • Create a custom event processor by subclassing EventProcessor and overriding the process_event method.
    • Pass the custom processor to start_stream.
  3. Verify Cursor Handling:

    • Interrupt the stream, then restart the script to verify that it resumes from the saved cursor position.

This refactor improves the flexibility, reliability, and maintainability of the gRPC streaming code, making it well-suited for long-running Solana data processing tasks.

@dkdocs dkdocs marked this pull request as draft November 11, 2024 14:21
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