From 3de397f4be997a084b941d6a6af5e09a3f344d9d Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Tue, 7 Nov 2017 15:03:28 -0500 Subject: [PATCH] make actions per worker --- ofborg/src/bin/builder.rs | 9 +++++++-- ofborg/src/message/buildjob.rs | 2 ++ ofborg/src/worker.rs | 22 +++++++--------------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/ofborg/src/bin/builder.rs b/ofborg/src/bin/builder.rs index ad5daec..02c4d8a 100644 --- a/ofborg/src/bin/builder.rs +++ b/ofborg/src/bin/builder.rs @@ -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) -> Result { @@ -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())?; diff --git a/ofborg/src/message/buildjob.rs b/ofborg/src/message/buildjob.rs index 2f6a61a..b41b957 100644 --- a/ofborg/src/message/buildjob.rs +++ b/ofborg/src/message/buildjob.rs @@ -10,3 +10,5 @@ pub struct BuildJob { pub fn from(data: &Vec) -> Result { return serde_json::from_slice(&data); } + +pub struct Actions{} diff --git a/ofborg/src/worker.rs b/ofborg/src/worker.rs index 6f3bf8f..5b8515e 100644 --- a/ofborg/src/worker.rs +++ b/ofborg/src/worker.rs @@ -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) -> Result; + + fn job_to_actions(&self, channel: &mut Channel, job: &Self::J) -> Self::A; } pub fn new(worker: T) -> Worker { @@ -34,19 +37,8 @@ impl Consumer for Worker { headers: BasicProperties, body: Vec) { - 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(); } }