mirror of
https://github.com/gorules/zen.git
synced 2026-10-05 00:02:26 +00:00
feat: policy engine (#450)
* feat: policy engine * fix: cargo fmt * fix: resolve issues with miri
This commit is contained in:
@@ -16,7 +16,9 @@ impl PyZenDecisionContent {
|
||||
pub fn new(data: &str) -> PyResult<Self> {
|
||||
let mut content: DecisionContent =
|
||||
serde_json::from_str(data).context("Failed to parse JSON")?;
|
||||
content.compile();
|
||||
if let DecisionContent::Graph(g) = &mut content {
|
||||
g.compile();
|
||||
}
|
||||
Ok(Self(Arc::new(content)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,13 +168,17 @@ impl PyZenEngine {
|
||||
}
|
||||
|
||||
pub fn create_decision(&self, content: PyZenDecisionContentJson) -> PyResult<PyZenDecision> {
|
||||
let decision = self.engine.create_decision(content.0 .0);
|
||||
let decision = self
|
||||
.engine
|
||||
.create_decision(content.0 .0)
|
||||
.map_err(|e| anyhow!(e.to_string()))?;
|
||||
Ok(PyZenDecision::from(decision))
|
||||
}
|
||||
|
||||
pub fn get_decision<'py>(&'py self, _py: Python<'py>, key: &str) -> PyResult<PyZenDecision> {
|
||||
let decision = block_on(self.engine.get_decision(key))
|
||||
.context("Failed to find decision with given key")?;
|
||||
.context("Failed to find decision with given key")?
|
||||
.map_err(|e| anyhow!(e.to_string()))?;
|
||||
|
||||
Ok(PyZenDecision::from(decision))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user