use super::{ConnectionServices, LimitsConfig, ServerError};
impl crate::services::context_watch::ContextFeed for super::services::ConnectionSubscription {
fn next_reading(&mut self) -> Option<(String, Vec<u8>)> {
self.try_next()
.map(|envelope| (envelope.message_id.as_uuid().to_string(), envelope.payload))
}
}
pub fn start_context_watch(
services: &dyn ConnectionServices,
bindings: &crate::services::production::ServiceBindings,
limits: &LimitsConfig,
) -> Result<Option<crate::services::context_watch::ContextWatch>, ServerError> {
if !bindings.watches_context() {
return Ok(None);
}
let wake = crate::services::context_watch::ContextWake::new();
let install = liminal::channel::InboxInstall {
budget: liminal::channel::ConnectionInboxBudget::new(limits.max_connection_inbox_bytes),
depth_cap: limits.max_subscription_inbox_depth,
notifier: Some(wake.notifier()),
capacity: None,
};
let subscription = services.subscribe(
crate::services::ServiceKind::ContextWatch.subject_shape(),
&[],
Some(install),
)?;
crate::services::context_watch::ContextWatch::start(
subscription,
wake,
bindings.context_reporter(),
)
.map(Some)
.map_err(|error| ServerError::ConfigValidation {
message: error.to_string(),
})
}