mirror of
https://github.com/Xevion/banner.git
synced 2025-12-14 20:11:05 -06:00
chore: remove dummy service
This commit is contained in:
15
src/main.rs
15
src/main.rs
@@ -6,7 +6,7 @@ use tracing_subscriber::{EnvFilter, FmtSubscriber};
|
|||||||
use crate::bot::{Data, age};
|
use crate::bot::{Data, age};
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::services::manager::ServiceManager;
|
use crate::services::manager::ServiceManager;
|
||||||
use crate::services::{ServiceResult, bot::BotService, dummy::DummyService, run_service};
|
use crate::services::{ServiceResult, bot::BotService, run_service};
|
||||||
use figment::{Figment, providers::Env};
|
use figment::{Figment, providers::Env};
|
||||||
|
|
||||||
mod bot;
|
mod bot;
|
||||||
@@ -42,13 +42,21 @@ async fn main() {
|
|||||||
// Configure the client with your Discord bot token in the environment.
|
// Configure the client with your Discord bot token in the environment.
|
||||||
let intents = GatewayIntents::non_privileged();
|
let intents = GatewayIntents::non_privileged();
|
||||||
|
|
||||||
|
let bot_target_guild = config.bot_target_guild;
|
||||||
|
|
||||||
let framework = poise::Framework::builder()
|
let framework = poise::Framework::builder()
|
||||||
.options(poise::FrameworkOptions {
|
.options(poise::FrameworkOptions {
|
||||||
commands: vec![age()],
|
commands: vec![age()],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.setup(|ctx, _ready, framework| {
|
.setup(move |ctx, _ready, framework| {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
|
poise::builtins::register_in_guild(
|
||||||
|
ctx,
|
||||||
|
&framework.options().commands,
|
||||||
|
bot_target_guild.into(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
||||||
Ok(Data {})
|
Ok(Data {})
|
||||||
})
|
})
|
||||||
@@ -68,13 +76,10 @@ async fn main() {
|
|||||||
|
|
||||||
// Create and add services
|
// Create and add services
|
||||||
let bot_service = Box::new(BotService::new(client));
|
let bot_service = Box::new(BotService::new(client));
|
||||||
let dummy_service = Box::new(DummyService::new("background"));
|
|
||||||
|
|
||||||
let bot_handle = tokio::spawn(run_service(bot_service, service_manager.subscribe()));
|
let bot_handle = tokio::spawn(run_service(bot_service, service_manager.subscribe()));
|
||||||
let dummy_handle = tokio::spawn(run_service(dummy_service, service_manager.subscribe()));
|
|
||||||
|
|
||||||
service_manager.add_service("bot".to_string(), bot_handle);
|
service_manager.add_service("bot".to_string(), bot_handle);
|
||||||
service_manager.add_service("background".to_string(), dummy_handle);
|
|
||||||
|
|
||||||
// Set up CTRL+C signal handling
|
// Set up CTRL+C signal handling
|
||||||
let ctrl_c = async {
|
let ctrl_c = async {
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
use super::Service;
|
|
||||||
use std::time::Duration;
|
|
||||||
use tracing::{error, info};
|
|
||||||
|
|
||||||
/// Dummy service implementation for demonstration
|
|
||||||
pub struct DummyService {
|
|
||||||
name: &'static str,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DummyService {
|
|
||||||
pub fn new(name: &'static str) -> Self {
|
|
||||||
Self { name }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl Service for DummyService {
|
|
||||||
fn name(&self) -> &'static str {
|
|
||||||
self.name
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn run(&mut self) -> Result<(), anyhow::Error> {
|
|
||||||
let mut counter = 0;
|
|
||||||
loop {
|
|
||||||
tokio::time::sleep(Duration::from_secs(10)).await;
|
|
||||||
counter += 1;
|
|
||||||
info!(service = self.name, "Service heartbeat ({counter})");
|
|
||||||
|
|
||||||
// Simulate service failure after 60 seconds for demo
|
|
||||||
if counter >= 6 {
|
|
||||||
error!(service = self.name, "Service encountered an error");
|
|
||||||
return Err(anyhow::anyhow!("Service error"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn shutdown(&mut self) -> Result<(), anyhow::Error> {
|
|
||||||
// Simulate cleanup work
|
|
||||||
tokio::time::sleep(Duration::from_millis(6000)).await;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,6 @@ use tokio::sync::broadcast;
|
|||||||
use tracing::{error, info, warn};
|
use tracing::{error, info, warn};
|
||||||
|
|
||||||
pub mod bot;
|
pub mod bot;
|
||||||
pub mod dummy;
|
|
||||||
pub mod manager;
|
pub mod manager;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|||||||
Reference in New Issue
Block a user