add id getter for message body

This commit is contained in:
rmanach 2023-04-18 21:28:27 +02:00
parent 0c3a8acae0
commit 6d26f1032d
2 changed files with 14 additions and 3 deletions

View File

@ -1,6 +1,8 @@
#[allow(dead_code)]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum Message { pub enum Message {
CheckDeploy(MessageBody), CheckDeploy(MessageBody),
StopManager,
} }
#[allow(dead_code)] #[allow(dead_code)]
@ -10,6 +12,12 @@ pub struct MessageBody {
content: String, content: String,
} }
impl MessageBody {
pub fn get_id(&self) -> u32 {
self.id
}
}
impl Message { impl Message {
pub fn check_deploy(id: u32, content: &str) -> Self { pub fn check_deploy(id: u32, content: &str) -> Self {
let body = MessageBody { let body = MessageBody {

View File

@ -19,7 +19,7 @@ impl CheckHandler {
impl Handler for CheckHandler { impl Handler for CheckHandler {
fn handle(&self, res: Result<Message, String>) { fn handle(&self, res: Result<Message, String>) {
match res { match res {
Ok(_m) => todo!(), Ok(_m) => (),
Err(_e) => todo!(), Err(_e) => todo!(),
} }
} }
@ -36,12 +36,15 @@ impl DeployHandler {
fn manage_message(&self, message: Message) { fn manage_message(&self, message: Message) {
match message { match message {
Message::CheckDeploy(_body) => { Message::CheckDeploy(body) => {
let guard = self.sender.lock().unwrap(); let guard = self.sender.lock().unwrap();
if let Err(e) = guard.send(Job::new(1, JobAction::MegaportCheckDeploy)) { let id: i32 = body.get_id().try_into().unwrap();
if let Err(e) = guard.send(Job::new(id, JobAction::MegaportCheckDeploy)) {
println!("[handler(deploy)] error: {}", e); println!("[handler(deploy)] error: {}", e);
} }
} }
Message::StopManager => todo!(),
} }
} }
} }