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