Simplify publishing serde jobs
This commit is contained in:
parent
80f720fe02
commit
fd3cc55b2a
|
@ -48,14 +48,11 @@ impl Actions {
|
||||||
};
|
};
|
||||||
|
|
||||||
return vec![
|
return vec![
|
||||||
worker::Action::Publish(worker::QueueMsg{
|
worker::publish_serde_action(
|
||||||
exchange: Some("build-results".to_owned()),
|
Some("build-results".to_owned()),
|
||||||
routing_key: None,
|
None,
|
||||||
mandatory: true,
|
&msg
|
||||||
immediate: false,
|
),
|
||||||
properties: Some(props),
|
|
||||||
content: serde_json::to_string(&msg).unwrap().into_bytes()
|
|
||||||
}),
|
|
||||||
worker::Action::Ack
|
worker::Action::Ack
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -69,21 +66,12 @@ impl Actions {
|
||||||
success: success
|
success: success
|
||||||
};
|
};
|
||||||
|
|
||||||
let props = protocol::basic::BasicProperties {
|
|
||||||
content_type: Some("application/json".to_owned()),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
return vec![
|
return vec![
|
||||||
worker::Action::Publish(worker::QueueMsg{
|
worker::publish_serde_action(
|
||||||
exchange: Some("build-results".to_owned()),
|
Some("build-results".to_owned()),
|
||||||
routing_key: None,
|
None,
|
||||||
mandatory: true,
|
&msg
|
||||||
immediate: false,
|
),
|
||||||
properties: Some(props),
|
|
||||||
content: serde_json::to_string(&msg).unwrap().into_bytes()
|
|
||||||
}),
|
|
||||||
worker::Action::Ack
|
worker::Action::Ack
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,21 +107,11 @@ impl worker::SimpleWorker for GitHubCommentWorker {
|
||||||
attrs: attrs,
|
attrs: attrs,
|
||||||
};
|
};
|
||||||
|
|
||||||
let props = BasicProperties {
|
response.push(worker::publish_serde_action(
|
||||||
content_type: Some("application/json".to_owned()),
|
Some("build-jobs".to_owned()),
|
||||||
..Default::default()
|
None,
|
||||||
};
|
&msg
|
||||||
|
));
|
||||||
response.push(
|
|
||||||
worker::Action::Publish(worker::QueueMsg{
|
|
||||||
exchange: Some("build-jobs".to_owned()),
|
|
||||||
routing_key: None,
|
|
||||||
mandatory: true,
|
|
||||||
immediate: false,
|
|
||||||
properties: Some(props),
|
|
||||||
content: serde_json::to_string(&msg).unwrap().into_bytes()
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
commentparser::Instruction::Eval => {
|
commentparser::Instruction::Eval => {
|
||||||
let msg = massrebuildjob::MassRebuildJob{
|
let msg = massrebuildjob::MassRebuildJob{
|
||||||
|
@ -129,21 +119,11 @@ impl worker::SimpleWorker for GitHubCommentWorker {
|
||||||
pr: pr_msg.clone(),
|
pr: pr_msg.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let props = BasicProperties {
|
response.push(worker::publish_serde_action(
|
||||||
content_type: Some("application/json".to_owned()),
|
None,
|
||||||
..Default::default()
|
Some("mass-rebuild-check-jobs".to_owned()),
|
||||||
};
|
&msg
|
||||||
|
));
|
||||||
response.push(
|
|
||||||
worker::Action::Publish(worker::QueueMsg{
|
|
||||||
exchange: None,
|
|
||||||
routing_key: Some("mass-rebuild-check-jobs".to_owned()),
|
|
||||||
mandatory: true,
|
|
||||||
immediate: false,
|
|
||||||
properties: Some(props),
|
|
||||||
content: serde_json::to_string(&msg).unwrap().into_bytes()
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,8 @@ use amqp::Basic;
|
||||||
use amqp::{Consumer, Channel};
|
use amqp::{Consumer, Channel};
|
||||||
use amqp::protocol::basic::{Deliver,BasicProperties};
|
use amqp::protocol::basic::{Deliver,BasicProperties};
|
||||||
use std::marker::Send;
|
use std::marker::Send;
|
||||||
|
use serde::Serialize;
|
||||||
|
use serde_json;
|
||||||
|
|
||||||
pub struct Worker<T: SimpleWorker> {
|
pub struct Worker<T: SimpleWorker> {
|
||||||
internal: T
|
internal: T
|
||||||
|
@ -31,6 +32,23 @@ pub struct QueueMsg {
|
||||||
pub content: Vec<u8>,
|
pub content: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn publish_serde_action<T: ?Sized>(exchange: Option<String>, routing_key: Option<String>, msg: &T) -> Action
|
||||||
|
where
|
||||||
|
T: Serialize {
|
||||||
|
let props = BasicProperties {
|
||||||
|
content_type: Some("application/json".to_owned()),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
return Action::Publish(QueueMsg{
|
||||||
|
exchange: exchange,
|
||||||
|
routing_key: routing_key,
|
||||||
|
mandatory: true,
|
||||||
|
immediate: false,
|
||||||
|
properties: Some(props),
|
||||||
|
content: serde_json::to_string(&msg).unwrap().into_bytes()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
pub trait SimpleWorker {
|
pub trait SimpleWorker {
|
||||||
type J;
|
type J;
|
||||||
|
|
Loading…
Reference in a new issue