From 1ae419d3b6f1f73be79940750c1ca8ba5e63d13d Mon Sep 17 00:00:00 2001 From: Wenxuan Zhang Date: Fri, 18 Feb 2022 16:44:25 +0800 Subject: [PATCH] feat(sdk/py): update online get api --- sdk/python/Cargo.lock | 4 ++-- sdk/python/Cargo.toml | 2 +- sdk/python/src/lib.rs | 23 ++++++++++++++++++++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/sdk/python/Cargo.lock b/sdk/python/Cargo.lock index d3eba2d0b..f7eee0a77 100644 --- a/sdk/python/Cargo.lock +++ b/sdk/python/Cargo.lock @@ -544,9 +544,9 @@ checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" [[package]] name = "oomclient" -version = "0.1.0" +version = "0.1.1-rc.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79260eab508142f45e630795b8a164f4c7acccae37041deff7d191272bbebf6e" +checksum = "51590c3f49412de8a94f874f5a5a3a9a1224e908d8637d09b65c36d4e406085f" dependencies = [ "async-stream", "futures-core", diff --git a/sdk/python/Cargo.toml b/sdk/python/Cargo.toml index a49a8f98c..096aa0d49 100644 --- a/sdk/python/Cargo.toml +++ b/sdk/python/Cargo.toml @@ -9,7 +9,7 @@ name = "oomclient" crate-type = ["cdylib"] [dependencies] -oomclient = "0.1.0" +oomclient = "0.1.1-rc.0" pyo3-asyncio = { version = "0.15", features = ["tokio-runtime"] } pyo3 = { version = "0.15", features = ["extension-module"] } tokio = { version = "1.15", features = ["macros", "rt-multi-thread"] } diff --git a/sdk/python/src/lib.rs b/sdk/python/src/lib.rs index 427336fdb..209323fa4 100644 --- a/sdk/python/src/lib.rs +++ b/sdk/python/src/lib.rs @@ -6,8 +6,9 @@ mod error; use convert::{err_to_py, py_to_value, value_map_to_py}; use error::Error; -use oomclient::Client as OomClient; +use oomclient::{Client as OomClient, OnlineGetFeatures}; use pyo3::{ + exceptions::PyException, prelude::*, types::{PyDict, PyType}, }; @@ -81,11 +82,27 @@ impl Client { /// features: A list of feature full names. /// A feature full name has the following format: <group_name>.<feature_name>, /// for example, txn_stats.count_7d. + /// group: All features of the group will be acquired if set. Conflict with `features` argument. /// /// Returns: /// A dict mapping feature full names to feature values. - #[pyo3(text_signature = "(entity_key, features)")] - pub fn online_get<'p>(&self, py: Python<'p>, entity_key: String, features: Vec) -> PyResult<&'p PyAny> { + #[pyo3(text_signature = "(entity_key, features=None, group=None)")] + #[args(features = "None", group = "None")] + pub fn online_get<'p>( + &self, + py: Python<'p>, + entity_key: String, + features: Option>, + group: Option, + ) -> PyResult<&'p PyAny> { + let features = match (features, group) { + (Some(features), None) => OnlineGetFeatures::FeatureNames(features), + (None, Some(group)) => OnlineGetFeatures::GroupName(group), + _ => + return Err(PyException::new_err( + "features and group cannot exist or absent at the same time", + )), + }; let mut inner = OomClient::clone(&self.inner); future_into_py(py, async move { inner