Skip to content

Commit

Permalink
feat(python): add non-graceful mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rasendubi committed Aug 22, 2024
1 parent bca541c commit eba132f
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions python-sdk/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
use std::{collections::HashMap, ops::Deref, sync::Arc, time::Duration};
use std::{
collections::HashMap,
ops::Deref,
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
time::Duration,
};

use pyo3::{
exceptions::{PyRuntimeError, PyTypeError},
Expand Down Expand Up @@ -112,6 +120,7 @@ pub struct EppoClient {
configuration_store: Arc<ConfigurationStore>,
poller_thread: PollerThread,
assignment_logger: Py<AssignmentLogger>,
is_graceful_mode: AtomicBool,
}

#[pymethods]
Expand Down Expand Up @@ -312,6 +321,11 @@ impl EppoClient {
Ok(EvaluationResult::from_bandit_result(py, result))
}

fn set_is_graceful_mode(&self, is_graceful_mode: bool) {
self.is_graceful_mode
.store(is_graceful_mode, Ordering::Release);
}

// Implementing [Garbage Collector integration][1] in case user's `AssignmentLogger` holds a
// reference to `EppoClient`. This will allow the GC to detect this cycle and break it.
//
Expand Down Expand Up @@ -412,6 +426,7 @@ impl EppoClient {
PyRuntimeError::new_err(format!("Config.assignment_logger is None"))
})?
.clone_ref(py),
is_graceful_mode: AtomicBool::new(config.is_graceful_mode),
})
}

Expand All @@ -437,8 +452,7 @@ impl EppoClient {
let assignment = match result {
Ok(assignment) => assignment,
Err(err) => {
let graceful_mode = true;
if graceful_mode {
if self.is_graceful_mode.load(Ordering::Acquire) {
None
} else {
return Err(PyErr::new::<PyRuntimeError, _>(err.to_string()));
Expand Down

0 comments on commit eba132f

Please sign in to comment.