feat: add replay-stream-tasks pattern support
This commit is contained in:
@@ -5,17 +5,30 @@ use crate::{
|
||||
storage::StorageService,
|
||||
};
|
||||
|
||||
pub trait AppContextTrait: Send + Sync {
|
||||
fn logger(&self) -> &LoggerService;
|
||||
fn db(&self) -> &DatabaseService;
|
||||
fn config(&self) -> &AppConfig;
|
||||
fn cache(&self) -> &CacheService;
|
||||
fn mikan(&self) -> &MikanClient;
|
||||
fn auth(&self) -> &AuthService;
|
||||
fn graphql(&self) -> &GraphQLService;
|
||||
fn storage(&self) -> &StorageService;
|
||||
fn working_dir(&self) -> &String;
|
||||
fn environment(&self) -> &Environment;
|
||||
}
|
||||
|
||||
pub struct AppContext {
|
||||
pub logger: LoggerService,
|
||||
pub db: DatabaseService,
|
||||
pub config: AppConfig,
|
||||
pub cache: CacheService,
|
||||
pub mikan: MikanClient,
|
||||
pub auth: AuthService,
|
||||
pub graphql: GraphQLService,
|
||||
pub storage: StorageService,
|
||||
pub working_dir: String,
|
||||
pub environment: Environment,
|
||||
logger: LoggerService,
|
||||
db: DatabaseService,
|
||||
config: AppConfig,
|
||||
cache: CacheService,
|
||||
mikan: MikanClient,
|
||||
auth: AuthService,
|
||||
graphql: GraphQLService,
|
||||
storage: StorageService,
|
||||
working_dir: String,
|
||||
environment: Environment,
|
||||
}
|
||||
|
||||
impl AppContext {
|
||||
@@ -48,3 +61,35 @@ impl AppContext {
|
||||
})
|
||||
}
|
||||
}
|
||||
impl AppContextTrait for AppContext {
|
||||
fn logger(&self) -> &LoggerService {
|
||||
&self.logger
|
||||
}
|
||||
fn db(&self) -> &DatabaseService {
|
||||
&self.db
|
||||
}
|
||||
fn config(&self) -> &AppConfig {
|
||||
&self.config
|
||||
}
|
||||
fn cache(&self) -> &CacheService {
|
||||
&self.cache
|
||||
}
|
||||
fn mikan(&self) -> &MikanClient {
|
||||
&self.mikan
|
||||
}
|
||||
fn auth(&self) -> &AuthService {
|
||||
&self.auth
|
||||
}
|
||||
fn graphql(&self) -> &GraphQLService {
|
||||
&self.graphql
|
||||
}
|
||||
fn storage(&self) -> &StorageService {
|
||||
&self.storage
|
||||
}
|
||||
fn working_dir(&self) -> &String {
|
||||
&self.working_dir
|
||||
}
|
||||
fn environment(&self) -> &Environment {
|
||||
&self.environment
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use axum::Router;
|
||||
use futures::try_join;
|
||||
use tokio::signal;
|
||||
|
||||
use super::{builder::AppBuilder, context::AppContext};
|
||||
use super::{builder::AppBuilder, context::AppContextTrait};
|
||||
use crate::{
|
||||
errors::RResult,
|
||||
web::{
|
||||
@@ -14,7 +14,7 @@ use crate::{
|
||||
};
|
||||
|
||||
pub struct App {
|
||||
pub context: Arc<AppContext>,
|
||||
pub context: Arc<dyn AppContextTrait>,
|
||||
pub builder: AppBuilder,
|
||||
}
|
||||
|
||||
@@ -25,14 +25,14 @@ impl App {
|
||||
|
||||
pub async fn serve(&self) -> RResult<()> {
|
||||
let context = &self.context;
|
||||
let config = &context.config;
|
||||
let config = context.config();
|
||||
let listener = tokio::net::TcpListener::bind(&format!(
|
||||
"{}:{}",
|
||||
config.server.binding, config.server.port
|
||||
))
|
||||
.await?;
|
||||
|
||||
let mut router = Router::<Arc<AppContext>>::new();
|
||||
let mut router = Router::<Arc<dyn AppContextTrait>>::new();
|
||||
|
||||
let (graphqlc, oidcc) = try_join!(
|
||||
controller::graphql::create(context.clone()),
|
||||
|
||||
@@ -8,5 +8,5 @@ pub use core::App;
|
||||
|
||||
pub use builder::AppBuilder;
|
||||
pub use config::AppConfig;
|
||||
pub use context::AppContext;
|
||||
pub use context::{AppContext, AppContextTrait};
|
||||
pub use env::Environment;
|
||||
|
||||
Reference in New Issue
Block a user