From 14fefdd51c67a774c482d39a1fd9c02824b39b38 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Mon, 22 Jan 2018 09:48:30 -0500 Subject: [PATCH] Create a log message generator for testing log saving / display --- ofborg/src/bin/log-message-generator.rs | 62 +++++++++++++++++++++++++ ofborg/src/notifyworker.rs | 2 +- ofborg/src/tasks/build.rs | 9 ++-- 3 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 ofborg/src/bin/log-message-generator.rs diff --git a/ofborg/src/bin/log-message-generator.rs b/ofborg/src/bin/log-message-generator.rs new file mode 100644 index 0000000..1adfeb5 --- /dev/null +++ b/ofborg/src/bin/log-message-generator.rs @@ -0,0 +1,62 @@ +extern crate ofborg; +extern crate amqp; +extern crate env_logger; + +use std::env; +use std::time::Duration; +use std::thread; + +use amqp::Session; +use ofborg::message::{Pr, Repo}; + +use ofborg::config; +use ofborg::notifyworker; +use ofborg::tasks::build; +use ofborg::message::buildjob; + +fn main() { + let cfg = config::load(env::args().nth(1).unwrap().as_ref()); + ofborg::setup_log(); + + let mut session = Session::open_url(&cfg.rabbitmq.as_uri()).unwrap(); + println!("Connected to rabbitmq"); + + println!("About to open channel #1"); + let mut chan = session.open_channel(1).unwrap(); + + let mut receiver = notifyworker::ChannelNotificationReceiver::new(&mut chan, 0); + let job = buildjob::BuildJob { + attrs: vec![], + pr: Pr { + head_sha: String::from("bogus"), + number: 1, + target_branch: Some("master".to_owned()), + }, + repo: Repo { + clone_url: String::from("bogus"), + full_name: "test-git".to_owned(), + name: "nixos".to_owned(), + owner: "ofborg-test".to_owned(), + }, + subset: None, + logs: Some(( + Some(String::from("logs")), + Some(String::from("build.log")), + )), + statusreport: Some((Some(String::from("build-results")), None)), + }; + + loop { + println!("Starting a new build simulation"); + let mut actions = + build::JobActions::new(&cfg.nix.system, &cfg.runner.identity, &job, &mut receiver); + actions.log_started(); + + for i in 1..51 { + actions.log_line(&format!("Simulated log line #{:?}/50", i)); + thread::sleep(Duration::from_secs(1)) + } + + thread::sleep(Duration::from_secs(10)) + } +} diff --git a/ofborg/src/notifyworker.rs b/ofborg/src/notifyworker.rs index a38d1b8..76bc2ab 100644 --- a/ofborg/src/notifyworker.rs +++ b/ofborg/src/notifyworker.rs @@ -47,7 +47,7 @@ pub struct ChannelNotificationReceiver<'a> { } impl<'a> ChannelNotificationReceiver<'a> { - fn new(channel: &'a mut Channel, delivery_tag: u64) -> ChannelNotificationReceiver<'a> { + pub fn new(channel: &'a mut Channel, delivery_tag: u64) -> ChannelNotificationReceiver<'a> { return ChannelNotificationReceiver { channel: channel, delivery_tag: delivery_tag, diff --git a/ofborg/src/tasks/build.rs b/ofborg/src/tasks/build.rs index 16b16ba..eaa0493 100644 --- a/ofborg/src/tasks/build.rs +++ b/ofborg/src/tasks/build.rs @@ -53,7 +53,7 @@ impl BuildWorker { } } -struct JobActions<'a, 'b> { +pub struct JobActions<'a, 'b> { system: String, identity: String, receiver: &'a mut notifyworker::NotificationReceiver, @@ -67,7 +67,7 @@ struct JobActions<'a, 'b> { } impl<'a, 'b> JobActions<'a, 'b> { - fn new( + pub fn new( system: &str, identity: &str, job: &'b buildjob::BuildJob, @@ -402,7 +402,10 @@ mod tests { owner: "ofborg-test".to_owned(), }, subset: None, - logs: Some((Some(String::from("logs")), Some(String::from("build.log")))), + logs: Some(( + Some(String::from("logs")), + Some(String::from("build.log")), + )), statusreport: Some((Some(String::from("build-results")), None)), };