Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
[package]
name = "lum"
version = "0.2.1"
authors = ["Torben Schweren"]
edition = "2021"
rust-version = "1.80.0"
description = "Lum Discord Bot"
license= "MIT"
readme = "README.md"
authors = ["Torben Schweren"]
repository = "https://github.com/Kitt3120/lum"
license= "MIT"
keywords = ["chat", "discord", "bot", "framework"]
categories = ["chat", "discord", "framework"]

[profile.release]
debug = false
opt-level = 3
lto = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[profile.dev]
debug = true
opt-level = 0
lto = false

[dependencies]
async-trait = "0.1.83"
Expand Down
1 change: 0 additions & 1 deletion rustfmt.toml

This file was deleted.

13 changes: 9 additions & 4 deletions src/event/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ where
S: Into<String>,
{
let (sender, receiver) = channel(buffer);
let subscriber = Subscriber::new(name, log_on_error, remove_on_error, Callback::Channel(sender));
let subscriber = Subscriber::new(
name,
log_on_error,
remove_on_error,
Callback::Channel(sender),
);

let subscription = Subscription::from(&subscriber);
let receiver_subscription = ReceiverSubscription::new(subscription, receiver);
Expand Down Expand Up @@ -116,9 +121,9 @@ where
let subscription_to_remove = subscription.into();

let mut subscribers = self.subscribers.lock().await;
let index = subscribers
.iter()
.position(|subscription_of_event| subscription_of_event.uuid == subscription_to_remove.uuid);
let index = subscribers.iter().position(|subscription_of_event| {
subscription_of_event.uuid == subscription_to_remove.uuid
});

if let Some(index) = index {
subscribers.remove(index);
Expand Down
8 changes: 6 additions & 2 deletions src/event/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ where

pub async fn dispatch(&self, data: Arc<T>) -> Result<(), DispatchError<T>> {
match &self.callback {
Callback::Channel(sender) => sender.send(data).await.map_err(DispatchError::ChannelSend),
Callback::Channel(sender) => {
sender.send(data).await.map_err(DispatchError::ChannelSend)
}
Callback::Closure(closure) => closure(data).map_err(DispatchError::Closure),
Callback::AsyncClosure(closure) => closure(data).await.map_err(DispatchError::AsyncClosure),
Callback::AsyncClosure(closure) => {
closure(data).await.map_err(DispatchError::AsyncClosure)
}
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ async fn main() {
let config = match config_handler.load_config() {
Ok(config) => config,
Err(err) => {
error!("Error reading config file: {}\n{} will exit.", err, BOT_NAME);
error!(
"Error reading config file: {}\n{} will exit.",
err, BOT_NAME
);
return;
}
};
Expand All @@ -39,7 +42,10 @@ async fn main() {

fn setup_logger() {
if let Err(error) = log::setup() {
panic!("Error setting up the Logger: {}\n{} will exit.", error, BOT_NAME);
panic!(
"Error setting up the Logger: {}\n{} will exit.",
error, BOT_NAME
);
}
}

Expand Down
23 changes: 18 additions & 5 deletions src/service/discord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
all::{GatewayIntents, Ready},
async_trait,
client::{self, Cache, Context},
framework::{standard::Configuration, StandardFramework},

Check warning on line 7 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-64)

use of deprecated struct `serenity::framework::standard::Configuration`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 7 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-64)

use of deprecated struct `serenity::framework::StandardFramework`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 7 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (macos-64)

use of deprecated struct `serenity::framework::standard::Configuration`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 7 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (macos-64)

use of deprecated struct `serenity::framework::StandardFramework`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 7 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (windows-64)

use of deprecated struct `serenity::framework::standard::Configuration`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 7 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (windows-64)

use of deprecated struct `serenity::framework::StandardFramework`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 7 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-64)

use of deprecated struct `serenity::framework::standard::Configuration`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 7 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-64)

use of deprecated struct `serenity::framework::StandardFramework`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 7 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (macos-64)

use of deprecated struct `serenity::framework::standard::Configuration`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 7 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (macos-64)

use of deprecated struct `serenity::framework::StandardFramework`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 7 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (windows-64)

use of deprecated struct `serenity::framework::standard::Configuration`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 7 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (windows-64)

use of deprecated struct `serenity::framework::StandardFramework`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling
gateway::{ShardManager, VoiceGatewayManager},
http::Http,
prelude::TypeMap,
Expand Down Expand Up @@ -62,8 +62,8 @@
async fn start(&mut self, _service_manager: Arc<ServiceManager>) -> Result<(), BoxedError> {
let client_ready_notify = Arc::new(Notify::new());

let framework = StandardFramework::new();

Check warning on line 65 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-64)

use of deprecated struct `serenity::framework::StandardFramework`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 65 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-64)

use of deprecated associated function `serenity::framework::StandardFramework::new`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 65 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (macos-64)

use of deprecated struct `serenity::framework::StandardFramework`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 65 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (macos-64)

use of deprecated associated function `serenity::framework::StandardFramework::new`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 65 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (windows-64)

use of deprecated struct `serenity::framework::StandardFramework`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 65 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (windows-64)

use of deprecated associated function `serenity::framework::StandardFramework::new`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 65 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-64)

use of deprecated struct `serenity::framework::StandardFramework`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 65 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-64)

use of deprecated associated function `serenity::framework::StandardFramework::new`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 65 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (macos-64)

use of deprecated struct `serenity::framework::StandardFramework`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 65 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (macos-64)

use of deprecated associated function `serenity::framework::StandardFramework::new`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 65 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (windows-64)

use of deprecated struct `serenity::framework::StandardFramework`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 65 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (windows-64)

use of deprecated associated function `serenity::framework::StandardFramework::new`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling
framework.configure(Configuration::new().prefix("!"));

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-64)

use of deprecated struct `serenity::framework::standard::Configuration`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-64)

use of deprecated method `serenity::framework::StandardFramework::configure`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-64)

use of deprecated associated function `serenity::framework::standard::Configuration::new`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-64)

use of deprecated method `serenity::framework::standard::Configuration::prefix`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (macos-64)

use of deprecated struct `serenity::framework::standard::Configuration`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (macos-64)

use of deprecated method `serenity::framework::StandardFramework::configure`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (macos-64)

use of deprecated associated function `serenity::framework::standard::Configuration::new`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (macos-64)

use of deprecated method `serenity::framework::standard::Configuration::prefix`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (windows-64)

use of deprecated struct `serenity::framework::standard::Configuration`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (windows-64)

use of deprecated method `serenity::framework::StandardFramework::configure`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (windows-64)

use of deprecated associated function `serenity::framework::standard::Configuration::new`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Build (windows-64)

use of deprecated method `serenity::framework::standard::Configuration::prefix`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-64)

use of deprecated struct `serenity::framework::standard::Configuration`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-64)

use of deprecated method `serenity::framework::StandardFramework::configure`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-64)

use of deprecated associated function `serenity::framework::standard::Configuration::new`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-64)

use of deprecated method `serenity::framework::standard::Configuration::prefix`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (macos-64)

use of deprecated struct `serenity::framework::standard::Configuration`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (macos-64)

use of deprecated method `serenity::framework::StandardFramework::configure`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (macos-64)

use of deprecated associated function `serenity::framework::standard::Configuration::new`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (macos-64)

use of deprecated method `serenity::framework::standard::Configuration::prefix`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (windows-64)

use of deprecated struct `serenity::framework::standard::Configuration`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (windows-64)

use of deprecated method `serenity::framework::StandardFramework::configure`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (windows-64)

use of deprecated associated function `serenity::framework::standard::Configuration::new`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

Check warning on line 66 in src/service/discord.rs

View workflow job for this annotation

GitHub Actions / Test (windows-64)

use of deprecated method `serenity::framework::standard::Configuration::prefix`: The standard framework is deprecated, and will be removed in 0.13. Please migrate to `poise` for command handling

let mut client = Client::builder(self.discord_token.as_str(), GatewayIntents::all())
.framework(framework)
Expand All @@ -79,16 +79,24 @@
}

if self.data.set(Arc::clone(&client.data)).is_err() {
error!("Could not set data OnceLock because it was already set. This should never happen.");
error!(
"Could not set data OnceLock because it was already set. This should never happen."
);
return Err("Could not set data OnceLock because it was already set.".into());
}

if self.http.set(Arc::clone(&client.http)).is_err() {
error!("Could not set http OnceLock because it was already set. This should never happen.");
error!(
"Could not set http OnceLock because it was already set. This should never happen."
);
return Err("Could not set http OnceLock because it was already set.".into());
}

if self.shard_manager.set(Arc::clone(&client.shard_manager)).is_err() {
if self
.shard_manager
.set(Arc::clone(&client.shard_manager))
.is_err()
{
error!(
"Could not set shard_manager OnceLock because it was already set. This should never happen."
);
Expand All @@ -98,7 +106,9 @@
if let Some(voice_manager) = &client.voice_manager {
if self.voice_manager.set(Arc::clone(voice_manager)).is_err() {
error!("Could not set voice_manager OnceLock because it was already set. This should never happen.");
return Err("Could not set voice_manager OnceLock because it was already set.".into());
return Err(
"Could not set voice_manager OnceLock because it was already set.".into(),
);
}
} else {
warn!("Voice manager is not available");
Expand Down Expand Up @@ -153,7 +163,10 @@

impl EventHandler {
pub fn new(client: Arc<OnceLock<Ready>>, ready_notify: Arc<Notify>) -> Self {
Self { client, ready_notify }
Self {
client,
ready_notify,
}
}
}

Expand Down
87 changes: 61 additions & 26 deletions src/service/service_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ use super::{
service::Service,
types::{OverallStatus, Priority, ShutdownError, StartupError, Status},
};
use crate::{
event::EventRepeater, service::Watchdog
};
use crate::{event::EventRepeater, service::Watchdog};
use log::{error, info, warn};
use std::{collections::HashMap, fmt::{self, Display}, mem, sync::{Arc, OnceLock, Weak}, time::Duration};
use std::{
collections::HashMap,
fmt::{self, Display},
mem,
sync::{Arc, OnceLock, Weak},
time::Duration,
};
use tokio::{
spawn,
sync::{Mutex, MutexGuard},
Expand All @@ -20,8 +24,10 @@ pub struct ServiceManagerBuilder {
}

impl ServiceManagerBuilder {
pub fn new() -> Self {
Self { services: Vec::new() }
pub fn new() -> Self {
Self {
services: Vec::new(),
}
}

//TODO: When Rust allows async closures, refactor this to use iterator methods instead of for loop
Expand Down Expand Up @@ -65,8 +71,8 @@ pub fn new() -> Self {

let result = arc.weak.set(weak);
if result.is_err() {
error!("Unable to set ServiceManager's Weak self-reference in ServiceManagerBuilder because it was already set. This should never happen. Shutting down ungracefully to prevent further undefined behavior.");
unreachable!("Unable to set ServiceManager's Weak self-reference in ServiceManagerBuilder because it was already set.");
error!("Unable to set ServiceManager's Weak self-reference in ServiceManagerBuilder because it was already set. This should never happen. Shutting down ungracefully to prevent further undefined behavior.");
unreachable!("Unable to set ServiceManager's Weak self-reference in ServiceManagerBuilder because it was already set.");
}

arc
Expand All @@ -86,8 +92,7 @@ impl ServiceManager {
ServiceManagerBuilder::new()
}

pub async fn manages_service(&self, service_id: &str) -> bool
{
pub async fn manages_service(&self, service_id: &str) -> bool {
for service in self.services.iter() {
let service_lock = service.lock().await;

Expand All @@ -99,7 +104,10 @@ impl ServiceManager {
false
}

pub async fn start_service(&self, service: Arc<Mutex<dyn Service>>) -> Result<(), StartupError> {
pub async fn start_service(
&self,
service: Arc<Mutex<dyn Service>>,
) -> Result<(), StartupError> {
let service_id = service.lock().await.info().id.clone();
if !self.manages_service(&service_id).await {
return Err(StartupError::ServiceNotManaged(service_id.clone()));
Expand All @@ -113,13 +121,18 @@ impl ServiceManager {
}

if self.has_background_task_registered(&service_id).await {
return Err(StartupError::BackgroundTaskAlreadyRunning(service_id.clone()));
return Err(StartupError::BackgroundTaskAlreadyRunning(
service_id.clone(),
));
}

let service_status_event = service_lock.info().status.as_ref();
let attachment_result = self.on_status_change.attach(service_status_event, 2).await;
if let Err(err) = attachment_result {
return Err(StartupError::StatusAttachmentFailed(service_id.clone(), err));
return Err(StartupError::StatusAttachmentFailed(
service_id.clone(),
err,
));
}

service_lock.info().status.set(Status::Starting).await;
Expand All @@ -133,7 +146,10 @@ impl ServiceManager {
}

//TODO: Clean up
pub async fn stop_service(&self, service: Arc<Mutex<dyn Service>>) -> Result<(), ShutdownError> {
pub async fn stop_service(
&self,
service: Arc<Mutex<dyn Service>>,
) -> Result<(), ShutdownError> {
let service_id = service.lock().await.info().id.clone();
if !(self.manages_service(&service_id).await) {
return Err(ShutdownError::ServiceNotManaged(service_id.clone()));
Expand All @@ -155,7 +171,10 @@ impl ServiceManager {
let service_status_event = service_lock.info().status.as_ref();
let detach_result = self.on_status_change.detach(service_status_event).await;
if let Err(err) = detach_result {
return Err(ShutdownError::StatusDetachmentFailed(service_id.clone(), err));
return Err(ShutdownError::StatusDetachmentFailed(
service_id.clone(),
err,
));
}

info!("Stopped service {}", service_lock.info().name);
Expand Down Expand Up @@ -305,7 +324,7 @@ impl ServiceManager {
.map(|line| line.len())
.max()
.unwrap_or(0);

let mut headline = String::from("Status overview\n");
headline.push_str("─".repeat(longest_width).as_str());
headline.push('\n');
Expand All @@ -322,7 +341,10 @@ impl ServiceManager {
Some(weak) => weak,
None => {
error!("ServiceManager's Weak self-reference was None while initializing service {}. This should never happen. Did you not use a ServiceManagerBuilder? Shutting down ungracefully to prevent further undefined behavior.", service.info().name);
unreachable!("ServiceManager's Weak self-reference was None while initializing service {}.", service.info().name);
unreachable!(
"ServiceManager's Weak self-reference was None while initializing service {}.",
service.info().name
);
}
};

Expand All @@ -335,7 +357,6 @@ impl ServiceManager {
}
};


//TODO: Add to config instead of hardcoding duration
let start = service.start(arc);
let timeout_result = timeout(Duration::from_secs(10), start).await;
Expand All @@ -351,7 +372,9 @@ impl ServiceManager {
.status
.set(Status::FailedToStart(error.to_string()))
.await;
return Err(StartupError::FailedToStartService(service.info().id.clone()));
return Err(StartupError::FailedToStartService(
service.info().id.clone(),
));
}
},
Err(error) => {
Expand All @@ -360,7 +383,9 @@ impl ServiceManager {
.status
.set(Status::FailedToStart(error.to_string()))
.await;
return Err(StartupError::FailedToStartService(service.info().id.clone()));
return Err(StartupError::FailedToStartService(
service.info().id.clone(),
));
}
}

Expand All @@ -386,7 +411,9 @@ impl ServiceManager {
.status
.set(Status::FailedToStop(error.to_string()))
.await;
return Err(ShutdownError::FailedToStopService(service.info().id.clone()));
return Err(ShutdownError::FailedToStopService(
service.info().id.clone(),
));
}
},
Err(error) => {
Expand All @@ -395,7 +422,9 @@ impl ServiceManager {
.status
.set(Status::FailedToStop(error.to_string()))
.await;
return Err(ShutdownError::FailedToStopService(service.info().id.clone()));
return Err(ShutdownError::FailedToStopService(
service.info().id.clone(),
));
}
}

Expand All @@ -412,7 +441,10 @@ impl ServiceManager {
service_lock: &MutexGuard<'_, dyn Service>,
service: Arc<Mutex<dyn Service>>,
) {
if self.has_background_task_registered(&service_lock.info().id).await {
if self
.has_background_task_registered(&service_lock.info().id)
.await
{
return;
}

Expand All @@ -433,14 +465,14 @@ impl ServiceManager {
"Background task of service {} ended unexpectedly! Service will be marked as failed.",
service.info().name
);

service
.info()
.status
.set(Status::RuntimeError("Background task ended unexpectedly!".to_string()))
.await;
}

Err(error) => {
error!(
"Background task of service {} ended with error: {}. Service will be marked as failed.",
Expand Down Expand Up @@ -470,7 +502,10 @@ impl ServiceManager {
}

async fn stop_background_task(&self, service_lock: &MutexGuard<'_, dyn Service>) {
if !self.has_background_task_registered(&service_lock.info().id).await {
if !self
.has_background_task_registered(&service_lock.info().id)
.await
{
return;
}

Expand Down
3 changes: 2 additions & 1 deletion src/service/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ pub type PinnedBoxedFuture<T> = Pin<Box<dyn Future<Output = T> + Send + Sync>>;
pub type PinnedBoxedFutureResult<T> = PinnedBoxedFuture<Result<T, BoxedError>>;

pub type LifetimedPinnedBoxedFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + Sync + 'a>>;
pub type LifetimedPinnedBoxedFutureResult<'a, T> = LifetimedPinnedBoxedFuture<'a, Result<T, BoxedError>>;
pub type LifetimedPinnedBoxedFutureResult<'a, T> =
LifetimedPinnedBoxedFuture<'a, Result<T, BoxedError>>;

#[derive(Debug, Clone)]
pub enum Status {
Expand Down
Loading