make actions per worker
This commit is contained in:
parent
0133c66887
commit
3de397f4be
|
@ -17,7 +17,6 @@ use ofborg::config;
|
|||
use ofborg::checkout;
|
||||
use ofborg::worker;
|
||||
use ofborg::message::buildjob;
|
||||
use ofborg::worker::Actions;
|
||||
|
||||
fn main() {
|
||||
let cfg = config::load(env::args().nth(1).unwrap().as_ref());
|
||||
|
@ -62,6 +61,7 @@ struct BuildWorker {
|
|||
|
||||
impl worker::SimpleWorker for BuildWorker {
|
||||
type J = buildjob::BuildJob;
|
||||
type A = buildjob::Actions;
|
||||
|
||||
fn msg_to_job(&self, method: &Deliver, headers: &BasicProperties,
|
||||
body: &Vec<u8>) -> Result<Self::J, String> {
|
||||
|
@ -75,7 +75,12 @@ impl worker::SimpleWorker for BuildWorker {
|
|||
}
|
||||
}
|
||||
|
||||
fn consumer(&self, job: buildjob::BuildJob, resp: Actions) -> Result<(), Error> {
|
||||
fn job_to_actions(&self, channel: &mut amqp::Channel, job: &buildjob::BuildJob) -> buildjob::Actions {
|
||||
return buildjob::Actions{};
|
||||
}
|
||||
|
||||
|
||||
fn consumer(&self, job: buildjob::BuildJob, resp: buildjob::Actions) -> Result<(), Error> {
|
||||
let project = self.cloner.project(job.repo.full_name, job.repo.clone_url);
|
||||
let co = project.clone_for("builder".to_string(),
|
||||
job.pr.number.to_string())?;
|
||||
|
|
|
@ -10,3 +10,5 @@ pub struct BuildJob {
|
|||
pub fn from(data: &Vec<u8>) -> Result<BuildJob, serde_json::error::Error> {
|
||||
return serde_json::from_slice(&data);
|
||||
}
|
||||
|
||||
pub struct Actions{}
|
||||
|
|
|
@ -13,10 +13,13 @@ pub struct Actions {
|
|||
|
||||
pub trait SimpleWorker {
|
||||
type J;
|
||||
fn consumer(&self, job: Self::J, resp: Actions) -> Result<(), Error>;
|
||||
type A;
|
||||
fn consumer(&self, job: Self::J, resp: Self::A) -> Result<(), Error>;
|
||||
|
||||
fn msg_to_job(&self, method: &Deliver, headers: &BasicProperties,
|
||||
body: &Vec<u8>) -> Result<Self::J, String>;
|
||||
|
||||
fn job_to_actions(&self, channel: &mut Channel, job: &Self::J) -> Self::A;
|
||||
}
|
||||
|
||||
pub fn new<T: SimpleWorker>(worker: T) -> Worker<T> {
|
||||
|
@ -34,19 +37,8 @@ impl <T: SimpleWorker + Send> Consumer for Worker<T> {
|
|||
headers: BasicProperties,
|
||||
body: Vec<u8>) {
|
||||
|
||||
match self.internal.msg_to_job(&method, &headers, &body) {
|
||||
Ok(job) => {
|
||||
let actions = Actions{};
|
||||
match self.internal.consumer(job, actions) {
|
||||
Ok(_) => { /* :) */ }
|
||||
Err(_) => {
|
||||
panic!("failed to run job!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
panic!(e);
|
||||
}
|
||||
}
|
||||
let job = self.internal.msg_to_job(&method, &headers, &body).unwrap();
|
||||
let actions = self.internal.job_to_actions(channel, &job);
|
||||
self.internal.consumer(job, actions).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue