move MAU tracking back to registry

This commit is contained in:
Shadowy Super Coder
2024-06-10 18:56:39 -06:00
parent 9487529992
commit 4afd3c2322
3 changed files with 38 additions and 36 deletions

View File

@@ -10,6 +10,7 @@ use reqwest::{Client, Proxy};
use rpc_toolkit::yajrc::RpcError;
use rpc_toolkit::{CallRemote, Context, Empty};
use serde::{Deserialize, Serialize};
use sqlx::PgPool;
use tokio::sync::broadcast::Sender;
use tracing::instrument;
use url::Url;
@@ -37,6 +38,8 @@ pub struct RegistryConfig {
pub tor_proxy: Option<Url>,
#[arg(short = 'd', long = "datadir")]
pub datadir: Option<PathBuf>,
#[arg(short = 'u', long = "pg-connection-url")]
pub pg_connection_url: Option<String>,
}
impl ContextConfig for RegistryConfig {
fn next(&mut self) -> Option<PathBuf> {
@@ -67,6 +70,7 @@ pub struct RegistryContextSeed {
pub rpc_continuations: RpcContinuations,
pub client: Client,
pub shutdown: Sender<()>,
pub pool: Option<PgPool>,
}
#[derive(Clone)]
@@ -94,6 +98,13 @@ impl RegistryContext {
.clone()
.map(Ok)
.unwrap_or_else(|| "socks5h://localhost:9050".parse())?;
let pool: Option<PgPool> = match &config.pg_connection_url {
Some(url) => match PgPool::connect(url.as_str()).await {
Ok(pool) => Some(pool),
Err(_) => None,
},
None => None,
};
Ok(Self(Arc::new(RegistryContextSeed {
hostname: config
.hostname
@@ -122,6 +133,7 @@ impl RegistryContext {
.build()
.with_kind(crate::ErrorKind::ParseUrl)?,
shutdown,
pool,
})))
}
}