remove unwraps from builder

Mostly the same behaviour, but the result syntax is a bit nicer.
This commit is contained in:
Daiderd Jordan 2020-04-29 22:41:15 +02:00
parent 8dfcccb93e
commit 8cb5bfd225
No known key found for this signature in database
GPG key ID: D02435D05B810C96

View file

@ -1,4 +1,5 @@
use std::env; use std::env;
use std::error::Error;
use std::path::Path; use std::path::Path;
use async_std::task; use async_std::task;
@ -8,11 +9,12 @@ use ofborg::easyamqp::{self, ChannelExt, ConsumerExt};
use ofborg::easylapin; use ofborg::easylapin;
use ofborg::{checkout, config, tasks}; use ofborg::{checkout, config, tasks};
fn main() { fn main() -> Result<(), Box<dyn Error>> {
let cfg = config::load(env::args().nth(1).unwrap().as_ref());
ofborg::setup_log(); ofborg::setup_log();
let arg = env::args().nth(1).expect("usage: builder <config>");
let cfg = config::load(arg.as_ref());
let cloner = checkout::cached_cloner(Path::new(&cfg.checkout.root)); let cloner = checkout::cached_cloner(Path::new(&cfg.checkout.root));
let nix = cfg.nix(); let nix = cfg.nix();
@ -26,8 +28,8 @@ fn main() {
panic!(); panic!();
}; };
let conn = easylapin::from_config(&cfg.rabbitmq).unwrap(); let conn = easylapin::from_config(&cfg.rabbitmq)?;
let mut chan = task::block_on(conn.create_channel()).unwrap(); let mut chan = task::block_on(conn.create_channel())?;
chan.declare_exchange(easyamqp::ExchangeConfig { chan.declare_exchange(easyamqp::ExchangeConfig {
exchange: "build-jobs".to_owned(), exchange: "build-jobs".to_owned(),
@ -37,8 +39,7 @@ fn main() {
auto_delete: false, auto_delete: false,
no_wait: false, no_wait: false,
internal: false, internal: false,
}) })?;
.unwrap();
let queue_name = if cfg.runner.build_all_jobs != Some(true) { let queue_name = if cfg.runner.build_all_jobs != Some(true) {
let queue_name = format!("build-inputs-{}", cfg.nix.system.clone()); let queue_name = format!("build-inputs-{}", cfg.nix.system.clone());
@ -49,8 +50,7 @@ fn main() {
exclusive: false, exclusive: false,
auto_delete: false, auto_delete: false,
no_wait: false, no_wait: false,
}) })?;
.unwrap();
queue_name queue_name
} else { } else {
warn!("Building all jobs, please don't use this unless you're"); warn!("Building all jobs, please don't use this unless you're");
@ -63,8 +63,7 @@ fn main() {
exclusive: true, exclusive: true,
auto_delete: true, auto_delete: true,
no_wait: false, no_wait: false,
}) })?;
.unwrap();
queue_name queue_name
}; };
@ -73,11 +72,9 @@ fn main() {
exchange: "build-jobs".to_owned(), exchange: "build-jobs".to_owned(),
routing_key: None, routing_key: None,
no_wait: false, no_wait: false,
}) })?;
.unwrap();
let handle = easylapin::NotifyChannel(chan) let handle = easylapin::NotifyChannel(chan).consume(
.consume(
tasks::build::BuildWorker::new( tasks::build::BuildWorker::new(
cloner, cloner,
nix, nix,
@ -92,12 +89,12 @@ fn main() {
no_wait: false, no_wait: false,
exclusive: false, exclusive: false,
}, },
) )?;
.unwrap();
info!("Fetching jobs from {}", &queue_name); info!("Fetching jobs from {}", &queue_name);
task::block_on(handle); task::block_on(handle);
drop(conn); // Close connection. drop(conn); // Close connection.
info!("Closed the session... EOF"); info!("Closed the session... EOF");
Ok(())
} }