Skip to content

Commit

Permalink
replace MutEventIngestion with RefCell
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecsl committed Feb 11, 2025
1 parent 89be230 commit a50e240
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
6 changes: 4 additions & 2 deletions eppo_core/src/event_ingestion/event_ingestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ impl EventIngestion {
/// @param key - The context entry key.
/// @param value - The context entry value, must be a string, number, boolean, or null. If value is
/// an object or an array, will throw an ArgumentError.
pub fn attach_context(&mut self, key: String, value: Value) -> Result<(), ContextError> {
self.event_delivery.attach_context(key, value)
pub fn attach_context(&mut self, key: String, value: Value) {
if let Err(err) = self.event_delivery.attach_context(key, value) {
log::warn!(target: "eppo", "failed to attach context: {}", err);
}
}

fn track_event(&self, event: Event) {
Expand Down
26 changes: 9 additions & 17 deletions ruby-sdk/ext/eppo_client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,6 @@ impl TryConvert for Config {
}
}

#[magnus::wrap(class = "EventIngestion")]
struct MutEventIngestion(RefCell<EventIngestion>);

impl MutEventIngestion {
pub fn new(event_ingestion: EventIngestion) -> Self {
Self(RefCell::new(event_ingestion))
}
}

#[magnus::wrap(class = "EppoClient::Core::Client")]
pub struct Client {
configuration_store: Arc<ConfigurationStore>,
Expand All @@ -76,7 +67,7 @@ pub struct Client {
// world.
background_thread: RefCell<Option<BackgroundThread>>,
configuration_poller: Option<ConfigurationPoller>,
event_ingestion: Option<MutEventIngestion>,
event_ingestion: RefCell<Option<EventIngestion>>,
}

impl Client {
Expand Down Expand Up @@ -129,14 +120,14 @@ impl Client {

let event_ingestion = config
.event_ingestion_config
.map(|config| MutEventIngestion::new(config.spawn(background_thread.runtime())));
.map(|config| config.spawn(background_thread.runtime()));

Client {
configuration_store,
evaluator,
background_thread: RefCell::new(Some(background_thread)),
configuration_poller,
event_ingestion,
event_ingestion: RefCell::new(event_ingestion),
}
}

Expand Down Expand Up @@ -265,7 +256,8 @@ impl Client {
}

pub fn set_context(&self, key: String, value: Value) -> Result<()> {
let Some(event_ingestion) = &self.event_ingestion else {
let mut binding = self.event_ingestion.borrow_mut();
let Some(event_ingestion) = binding.as_mut() else {
// Event ingestion is disabled, do nothing.
return Ok(());
};
Expand All @@ -276,13 +268,13 @@ impl Client {
)
})?;

event_ingestion.0.borrow_mut().attach_context(key, value);
event_ingestion.attach_context(key, value);

Ok(())
}

pub fn track(&self, event_type: String, payload: Value) -> Result<()> {
let Some(event_ingestion) = &self.event_ingestion else {
let binding = self.event_ingestion.borrow();
let Some(event_ingestion) = binding.as_ref() else {
// Event ingestion is disabled, do nothing.
return Ok(());
};
Expand All @@ -294,7 +286,7 @@ impl Client {
)
})?;

event_ingestion.0.borrow().track(event_type, payload);
event_ingestion.track(event_type, payload);

Ok(())
}
Expand Down

0 comments on commit a50e240

Please sign in to comment.