-
Notifications
You must be signed in to change notification settings - Fork 367
feat(python): add stream listing, update, delete, and purge #3701
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,7 @@ use crate::consumer::{ | |
| use crate::identifier::PyIdentifier; | ||
| use crate::receive_message::{PollingStrategy, ReceiveMessage}; | ||
| use crate::send_message::SendMessage; | ||
| use crate::stream::StreamDetails; | ||
| use crate::stream::{Stream, StreamDetails}; | ||
| use crate::topic::{Topic, TopicDetails}; | ||
| use tokio::sync::Mutex; | ||
|
|
||
|
|
@@ -168,6 +168,78 @@ impl IggyClient { | |
| }) | ||
| } | ||
|
|
||
| /// Gets all streams. | ||
| /// Returns a list of streams or a PyRuntimeError on failure. | ||
| #[gen_stub(override_return_type(type_repr="collections.abc.Awaitable[list[Stream]]", imports=("collections.abc")))] | ||
| fn get_streams<'a>(&self, py: Python<'a>) -> PyResult<Bound<'a, PyAny>> { | ||
| let inner = self.inner.clone(); | ||
| future_into_py(py, async move { | ||
| let streams = inner | ||
| .get_streams() | ||
| .await | ||
| .map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))?; | ||
| Ok(streams.into_iter().map(Stream::from).collect::<Vec<_>>()) | ||
| }) | ||
| } | ||
|
|
||
| /// Updates a stream's name by id. | ||
| /// Returns Ok(()) on successful update or a PyRuntimeError on failure. | ||
|
Comment on lines
+184
to
+186
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change to |
||
| #[gen_stub(override_return_type(type_repr="collections.abc.Awaitable[None]", imports=("collections.abc")))] | ||
| fn update_stream<'a>( | ||
| &self, | ||
| py: Python<'a>, | ||
| stream_id: PyIdentifier, | ||
| name: String, | ||
| ) -> PyResult<Bound<'a, PyAny>> { | ||
| let stream_id = Identifier::try_from(stream_id)?; | ||
| let inner = self.inner.clone(); | ||
| future_into_py(py, async move { | ||
| inner | ||
| .update_stream(&stream_id, &name) | ||
| .await | ||
| .map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))?; | ||
| Ok(()) | ||
| }) | ||
| } | ||
|
|
||
| /// Deletes a stream by id. | ||
| /// Returns Ok(()) on successful deletion or a PyRuntimeError on failure. | ||
|
Comment on lines
+205
to
+206
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change to |
||
| #[gen_stub(override_return_type(type_repr="collections.abc.Awaitable[None]", imports=("collections.abc")))] | ||
| fn delete_stream<'a>( | ||
| &self, | ||
| py: Python<'a>, | ||
| stream_id: PyIdentifier, | ||
| ) -> PyResult<Bound<'a, PyAny>> { | ||
| let stream_id = Identifier::try_from(stream_id)?; | ||
| let inner = self.inner.clone(); | ||
| future_into_py(py, async move { | ||
| inner | ||
| .delete_stream(&stream_id) | ||
| .await | ||
| .map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))?; | ||
| Ok(()) | ||
| }) | ||
| } | ||
|
|
||
| /// Purges all messages from a stream by id. | ||
| /// Returns Ok(()) on successful purge or a PyRuntimeError on failure. | ||
|
Comment on lines
+224
to
+225
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change to |
||
| #[gen_stub(override_return_type(type_repr="collections.abc.Awaitable[None]", imports=("collections.abc")))] | ||
| fn purge_stream<'a>( | ||
| &self, | ||
| py: Python<'a>, | ||
| stream_id: PyIdentifier, | ||
| ) -> PyResult<Bound<'a, PyAny>> { | ||
| let stream_id = Identifier::try_from(stream_id)?; | ||
| let inner = self.inner.clone(); | ||
| future_into_py(py, async move { | ||
| inner | ||
| .purge_stream(&stream_id) | ||
| .await | ||
| .map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))?; | ||
| Ok(()) | ||
| }) | ||
| } | ||
|
|
||
| /// Creates a new topic with the given parameters. | ||
| /// Returns Ok(()) on successful topic creation or a PyRuntimeError on failure. | ||
| #[pyo3( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ | |
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| use iggy::prelude::StreamDetails as RustStreamDetails; | ||
| use iggy::prelude::{Stream as RustStream, StreamDetails as RustStreamDetails}; | ||
| use pyo3::prelude::*; | ||
| use pyo3_stub_gen::derive::{gen_stub_pyclass, gen_stub_pymethods}; | ||
|
|
||
|
|
@@ -56,3 +56,39 @@ impl StreamDetails { | |
| self.inner.topics_count | ||
| } | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add the following doc: |
||
| #[gen_stub_pyclass] | ||
| #[pyclass] | ||
| pub struct Stream { | ||
| pub(crate) inner: RustStream, | ||
| } | ||
|
|
||
| impl From<RustStream> for Stream { | ||
| fn from(stream: RustStream) -> Self { | ||
| Self { inner: stream } | ||
| } | ||
| } | ||
|
|
||
| #[gen_stub_pymethods] | ||
| #[pymethods] | ||
| impl Stream { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add getters for created_at and size as well.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also write their docs as well. |
||
| #[getter] | ||
| pub fn id(&self) -> u32 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doc: |
||
| self.inner.id | ||
| } | ||
|
|
||
| #[getter] | ||
| pub fn name(&self) -> String { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doc: |
||
| self.inner.name.to_string() | ||
| } | ||
|
|
||
| #[getter] | ||
| pub fn messages_count(&self) -> u64 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doc: |
||
| self.inner.messages_count | ||
| } | ||
|
|
||
| #[getter] | ||
| pub fn topics_count(&self) -> u32 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doc: |
||
| self.inner.topics_count | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to