Create a log message generator for testing log saving / display
This commit is contained in:
parent
b80eb71f67
commit
14fefdd51c
62
ofborg/src/bin/log-message-generator.rs
Normal file
62
ofborg/src/bin/log-message-generator.rs
Normal file
|
@ -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))
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
|
|
|
@ -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)),
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue