Commit fd0bcfa2 authored by Ryan Olson's avatar Ryan Olson Committed by GitHub
Browse files

refactor: adding facades for runtimes (#187)

parent a52b3553
......@@ -43,7 +43,7 @@
use crate::discovery::Lease;
use super::{error, transports::nats::Slug, DistributedRuntime, Result};
use super::{error, traits::*, transports::nats::Slug, DistributedRuntime, Result, Runtime};
use crate::pipeline::network::{ingress::push_endpoint::PushEndpoint, PushWorkHandler};
use async_nats::{
......@@ -108,6 +108,18 @@ pub struct Component {
namespace: String,
}
impl DistributedRuntimeProvider for Component {
fn drt(&self) -> &DistributedRuntime {
&self.drt
}
}
impl RuntimeProvider for Component {
fn rt(&self) -> &Runtime {
self.drt.rt()
}
}
impl Component {
pub fn etcd_path(&self) -> String {
format!("{}/components/{}", self.namespace, self.name)
......@@ -160,6 +172,18 @@ pub struct Endpoint {
name: String,
}
impl DistributedRuntimeProvider for Endpoint {
fn drt(&self) -> &DistributedRuntime {
self.component.drt()
}
}
impl RuntimeProvider for Endpoint {
fn rt(&self) -> &Runtime {
self.component.rt()
}
}
impl Endpoint {
pub fn name(&self) -> &str {
&self.name
......@@ -206,6 +230,18 @@ pub struct Namespace {
name: String,
}
impl DistributedRuntimeProvider for Namespace {
fn drt(&self) -> &DistributedRuntime {
&self.runtime
}
}
impl RuntimeProvider for Namespace {
fn rt(&self) -> &Runtime {
self.runtime.rt()
}
}
impl Namespace {
pub(crate) fn new(runtime: DistributedRuntime, name: String) -> Result<Self> {
Ok(NamespaceBuilder::default()
......
......@@ -41,7 +41,7 @@ impl EndpointConfigBuilder {
pub async fn start(self) -> Result<()> {
let (endpoint, lease, handler) = self.build_internal()?.dissolve();
let lease = lease.unwrap_or(endpoint.component.drt.primary_lease());
let lease = lease.unwrap_or(endpoint.drt().primary_lease());
tracing::debug!(
"Starting endpoint: {}",
......
......@@ -79,3 +79,23 @@ pub struct DistributedRuntime {
// paths in etcd to a minimum.
component_registry: component::Registry,
}
pub mod traits {
use super::*;
/// A trait for objects taht proivde access to the [Runtime]
pub trait RuntimeProvider {
fn rt(&self) -> &Runtime;
}
/// A trait for objects that provide access to the [DistributedRuntime].
pub trait DistributedRuntimeProvider {
fn drt(&self) -> &DistributedRuntime;
}
impl RuntimeProvider for DistributedRuntime {
fn rt(&self) -> &Runtime {
&self.runtime
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment