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

Broadcast progress #36

Merged
merged 2 commits into from
Jan 4, 2024
Merged

Broadcast progress #36

merged 2 commits into from
Jan 4, 2024

Conversation

cpg314
Copy link
Collaborator

@cpg314 cpg314 commented Dec 28, 2023

This adds a Client::subscribe_progress method that allows subscribing to query progress events sent by the server. This is very useful to track the progress of larger queries.

The implementation uses a tokio::sync::broadcast, which only keeps the most recent events and sends them to subscribers. It is pretty short given that the blocks were already parsed.

This was briefly mentioned in #10 (comment)

Tests

This was tested through the "basic" example, adapted to display progress, and against a real database.

Matching progress against queries

Note that the Client::query* interfaces currently do not provide the ID of the query, so it is not yet possible to match progress events against exact queries. Nevertheless, the commit already populates the ID of queries, and returns it as part of the progress stream.

Later, The Client::query* should likely be adapted to return the query ID in addition to the Block stream. Then either:

  • We keep the same subscribe_progress interface
  • We return a progress stream for this exact query along with the query ID and the block stream.
  • We change the stream be a stream of enum representing either Block or Progress.

An alternative is to add a method to Client to return the ID of the query currently executing; this would be almost trivial.

This adds a `Client::subscribe_progress` method that allows subscribing to query progress events sent by the server.
This is very useful to track the progress of larger queries.
The implementation uses a `tokio::sync::broadcast`, which only keeps the most recent events and sends them to subscribers.

This was tested through the "basic" example, adapted to display progress, and against a real database.

Note that the `Client::query*` interfaces currently do not provide the ID of the query, so it is not yet possible to match progress events against exact queries.
Nevertheless, the commit already populates the ID of queries, and returns it as part of the progress stream.

Later, The `Client::query*` should likely be adapted to return the query ID in addition to the Block stream. Then either:
- We keep the same `subscribe_progress` interface
- We return a progress stream for this exact query along with the query ID and the block stream.
- We change the stream be a stream of enum representing either `Block` or `Progress`.

An alternative is to add a method to `Client` to return the ID of the query currently executing; this would be almost trivial.
- Into -> From
- Unnecessary cast
- Unnecessary try_into
- "Absurd comparisons" in the code generated by the derive macros
@cpg314 cpg314 merged commit a930c50 into Protryon:master Jan 4, 2024
@cpg314 cpg314 deleted the progress branch January 4, 2024 21:54
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