From d559383737546268a7ff08ca242a5c82722248e3 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Mon, 6 Nov 2017 12:55:37 -0500 Subject: [PATCH] try to do a type thing --- ofborg/src/bin/builder.rs | 61 +++++++++++++++++++++------------------ ofborg/src/worker.rs | 9 +----- 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/ofborg/src/bin/builder.rs b/ofborg/src/bin/builder.rs index 3fa0738..59e1797 100644 --- a/ofborg/src/bin/builder.rs +++ b/ofborg/src/bin/builder.rs @@ -11,42 +11,47 @@ use std::io::Error; use ofborg::checkout; use ofborg::worker; -use ofborg::worker::{Actions,StdPr,StdRepo,BuildJob}; +use ofborg::worker::{Actions,StdPr,StdRepo}; + + +pub struct BuildJob { + pub repo: StdRepo, + pub pr: StdPr, +} + fn main() { println!("Hello, world!"); - if false { - let mut session = Session::open_url("amqps://grahamc:cCbKQmwnRcd8kvPW9cjmMSkp@events.nix.gsc.io//").unwrap(); - let mut channel = session.open_channel(1).unwrap(); + let mut session = Session::open_url("amqps://grahamc:cCbKQmwnRcd8kvPW9cjmMSkp@events.nix.gsc.io//").unwrap(); + let mut channel = session.open_channel(1).unwrap(); - //queue: &str, passive: bool, durable: bool, exclusive: bool, auto_delete: bool, nowait: bool, arguments: Table - if let Err(problem) = channel.queue_declare("my_queue_name", false, true, false, false, false, Table::new()) { - println!("Failed to declare a queue: {:?}", problem); - process::exit(1); - } + //queue: &str, passive: bool, durable: bool, exclusive: bool, auto_delete: bool, nowait: bool, arguments: Table + if let Err(problem) = channel.queue_declare("my_queue_name", false, true, false, false, false, Table::new()) { + println!("Failed to declare a queue: {:?}", problem); + process::exit(1); + } - let cloner = checkout::cached_cloner(Path::new("/home/grahamc/.nix-test-rs")); + let cloner = checkout::cached_cloner(Path::new("/home/grahamc/.nix-test-rs")); - channel.basic_consume( - worker::new(BuildWorker{ - cloner: cloner - }), - "my_queue_name", - "lmao1", - false, - false, - false, - false, - Table::new() - ); + channel.basic_consume( + worker::new(BuildWorker{ + cloner: cloner + }), + "my_queue_name", + "lmao1", + false, + false, + false, + false, + Table::new() + ); - if let Err(result) = channel.basic_publish("", "my_queue_name", true, false, - protocol::basic::BasicProperties{ content_type: Some("text".to_string()), ..Default::default()}, (b"Hello from rust!").to_vec()) { - println!("Failed to publish: {:?}", result); - process::exit(1); - } + if let Err(result) = channel.basic_publish("", "my_queue_name", true, false, + protocol::basic::BasicProperties{ content_type: Some("text".to_string()), ..Default::default()}, (b"Hello from rust!").to_vec()) { + println!("Failed to publish: {:?}", result); + process::exit(1); } } @@ -55,7 +60,7 @@ struct BuildWorker { } impl worker::SimpleWorker for BuildWorker { - fn consumer(&self, job: BuildJob, resp: Actions) -> Result<(), Error> { + fn consumer(&self, job: BuildJob, resp: 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/worker.rs b/ofborg/src/worker.rs index b47e1f7..f3586c8 100644 --- a/ofborg/src/worker.rs +++ b/ofborg/src/worker.rs @@ -19,18 +19,11 @@ pub struct StdPr { pub head_sha: String, } - -pub struct BuildJob { - pub repo: StdRepo, - pub pr: StdPr, -} - - pub struct Actions { } pub trait SimpleWorker { - fn consumer(&self, job: BuildJob, resp: Actions) -> Result<(), Error>; + fn consumer(&self, job: J, resp: Actions) -> Result<(), Error>; } pub fn new(worker: T) -> Worker {