Skip to content

Commit

Permalink
Implements missing methods, minor refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
FedericoPonzi committed Nov 2, 2024
1 parent 44fb57e commit 01d2f19
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 68 deletions.
55 changes: 3 additions & 52 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 34 additions & 12 deletions horust/src/horust/commands_handler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::horust::bus::BusConnector;
use crate::horust::formats::{ServiceName, ServiceStatus};
use crate::horust::Event;
use anyhow::{anyhow, Result};
use horust_commands_lib::{CommandsHandlerTrait, HorustMsgServiceStatus};
use std::collections::HashMap;
use std::os::unix::net::UnixListener;
Expand Down Expand Up @@ -67,18 +68,39 @@ impl CommandsHandlerTrait for CommandsHandler {
fn get_unix_listener(&mut self) -> &mut UnixListener {
&mut self.uds_listener
}
fn get_service_status(&self, service_name: &str) -> anyhow::Result<HorustMsgServiceStatus> {
self.services
.get(service_name)
.map(from_service_status)
.ok_or_else(|| anyhow!("Error: service {service_name} not found."))
}
fn update_service_status(
&self,
_service_name: &str,
_new_status: HorustMsgServiceStatus,
) -> Result<()> {
/*
match self.services.get(service_name) {
None => bail!("Service {service_name} not found."),
Some(service_status) if from_service_status(service_status) != new_status => {
//self.bus.send_event(Event::Kill())
}
_ => (),
};*/
todo!();
}
}

fn get_service_status(&self, service_name: String) -> Option<HorustMsgServiceStatus> {
self.services.get(&service_name).map(|status| match status {
ServiceStatus::Starting => HorustMsgServiceStatus::Starting,
ServiceStatus::Started => HorustMsgServiceStatus::Started,
ServiceStatus::Running => HorustMsgServiceStatus::Running,
ServiceStatus::InKilling => HorustMsgServiceStatus::Inkilling,
ServiceStatus::Success => HorustMsgServiceStatus::Success,
ServiceStatus::Finished => HorustMsgServiceStatus::Finished,
ServiceStatus::FinishedFailed => HorustMsgServiceStatus::Finishedfailed,
ServiceStatus::Failed => HorustMsgServiceStatus::Failed,
ServiceStatus::Initial => HorustMsgServiceStatus::Initial,
})
fn from_service_status(status: &ServiceStatus) -> HorustMsgServiceStatus {
match status {
ServiceStatus::Starting => HorustMsgServiceStatus::Starting,
ServiceStatus::Started => HorustMsgServiceStatus::Started,
ServiceStatus::Running => HorustMsgServiceStatus::Running,
ServiceStatus::InKilling => HorustMsgServiceStatus::Inkilling,
ServiceStatus::Success => HorustMsgServiceStatus::Success,
ServiceStatus::Finished => HorustMsgServiceStatus::Finished,
ServiceStatus::FinishedFailed => HorustMsgServiceStatus::Finishedfailed,
ServiceStatus::Failed => HorustMsgServiceStatus::Failed,
ServiceStatus::Initial => HorustMsgServiceStatus::Initial,
}
}
3 changes: 0 additions & 3 deletions horust/src/horust/formats/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ pub enum ShuttingDown {
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Event {
PidChanged(ServiceName, Pid),
ServiceStarted(ServiceName),
// This command updates the service status.
StatusUpdate(ServiceName, ServiceStatus),
// This event represents a status change.
Expand All @@ -27,8 +26,6 @@ pub enum Event {
Run(ServiceName),
ShuttingDownInitiated(ShuttingDown),
HealthCheck(ServiceName, HealthinessStatus),
// TODO: to allow changes of service at supervisor:
//ServiceCreated(ServiceHandler)
}

impl Event {
Expand Down
2 changes: 1 addition & 1 deletion horust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct Opts {
/// Path to service file or a directory containing services to run. You can provide more than one argument to load multiple directories / services.
services_paths: Vec<PathBuf>,

#[arg(required = false, default_value = "/var/run/horust")]
#[arg(required = false, long, default_value = "/var/run/horust")]
/// Path to the folder that contains the Unix Domain Socket, used to communicate with horustctl
uds_folder_path: PathBuf,

Expand Down

0 comments on commit 01d2f19

Please sign in to comment.