Skip to content

Commit cdf8cbb

Browse files
authored
Merge pull request #500 from LnL7/lapin-test-binaries
lapin test binaries
2 parents 65699e5 + b464c29 commit cdf8cbb

File tree

3 files changed

+56
-32
lines changed

3 files changed

+56
-32
lines changed

ofborg/src/bin/build-faker.rs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1+
use std::env;
2+
use std::error::Error;
3+
4+
use async_std::task;
5+
use lapin::message::Delivery;
6+
use lapin::BasicProperties;
7+
18
use ofborg::commentparser;
29
use ofborg::config;
3-
use ofborg::easyamqp;
10+
use ofborg::easylapin;
411
use ofborg::message::{buildjob, Pr, Repo};
5-
use ofborg::notifyworker::{self, NotificationReceiver};
12+
use ofborg::notifyworker::NotificationReceiver;
613
use ofborg::worker;
714

8-
use std::env;
9-
10-
use tracing::info;
11-
12-
fn main() {
13-
let cfg = config::load(env::args().nth(1).unwrap().as_ref());
15+
fn main() -> Result<(), Box<dyn Error>> {
1416
ofborg::setup_log();
1517

16-
info!("Hello, world!");
17-
18-
let mut session = easyamqp::session_from_config(&cfg.rabbitmq).unwrap();
19-
info!("Connected to rabbitmq");
18+
let arg = env::args().nth(1).expect("usage: build-faker <config>");
19+
let cfg = config::load(arg.as_ref());
2020

21-
let mut channel = session.open_channel(1).unwrap();
21+
let conn = easylapin::from_config(&cfg.rabbitmq)?;
22+
let mut chan = task::block_on(conn.create_channel())?;
2223

2324
let repo_msg = Repo {
2425
clone_url: "https://github.com/nixos/ofborg.git".to_owned(),
@@ -46,7 +47,15 @@ fn main() {
4647
};
4748

4849
{
49-
let mut recv = notifyworker::ChannelNotificationReceiver::new(&mut channel, 0);
50+
let deliver = Delivery {
51+
delivery_tag: 0,
52+
exchange: "no-exchange".into(),
53+
routing_key: "".into(),
54+
redelivered: false,
55+
properties: BasicProperties::default(),
56+
data: vec![],
57+
};
58+
let mut recv = easylapin::ChannelNotificationReceiver::new(&mut chan, &deliver);
5059

5160
for _i in 1..2 {
5261
recv.tell(worker::publish_serde_action(
@@ -57,8 +66,5 @@ fn main() {
5766
}
5867
}
5968

60-
channel.close(200, "Bye").unwrap();
61-
info!("Closed the channel");
62-
session.close(200, "Good Bye");
63-
info!("Closed the session... EOF");
69+
Ok(())
6470
}

ofborg/src/bin/log-message-generator.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
1-
use ofborg::config;
2-
use ofborg::easyamqp;
3-
use ofborg::message::{buildjob, Pr, Repo};
4-
use ofborg::notifyworker;
5-
use ofborg::tasks::build;
6-
71
use std::env;
2+
use std::error::Error;
83
use std::thread;
94
use std::time::Duration;
105

6+
use async_std::task;
7+
use lapin::message::Delivery;
8+
use lapin::BasicProperties;
119
use tracing::info;
1210

13-
fn main() {
14-
let cfg = config::load(env::args().nth(1).unwrap().as_ref());
11+
use ofborg::config;
12+
use ofborg::easylapin;
13+
use ofborg::message::{buildjob, Pr, Repo};
14+
use ofborg::tasks::build;
15+
16+
fn main() -> Result<(), Box<dyn Error>> {
1517
ofborg::setup_log();
1618

17-
let mut session = easyamqp::session_from_config(&cfg.rabbitmq).unwrap();
18-
info!("Connected to rabbitmq");
19+
let arg = env::args()
20+
.nth(1)
21+
.expect("usage: log-message-generator <config>");
22+
let cfg = config::load(arg.as_ref());
1923

20-
info!("About to open channel #1");
21-
let mut chan = session.open_channel(1).unwrap();
24+
let conn = easylapin::from_config(&cfg.rabbitmq)?;
25+
let mut chan = task::block_on(conn.create_channel())?;
2226

23-
let mut receiver = notifyworker::ChannelNotificationReceiver::new(&mut chan, 0);
27+
let deliver = Delivery {
28+
delivery_tag: 0,
29+
exchange: "no-exchange".into(),
30+
routing_key: "".into(),
31+
redelivered: false,
32+
properties: BasicProperties::default(),
33+
data: vec![],
34+
};
35+
let mut receiver = easylapin::ChannelNotificationReceiver::new(&mut chan, &deliver);
2436
let job = buildjob::BuildJob {
2537
attrs: vec![],
2638
pr: Pr {

ofborg/src/easylapin.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,17 @@ impl<'a, W: SimpleWorker + 'a> ConsumerExt<'a, W> for WorkerChannel {
129129
}
130130
}
131131

132-
struct ChannelNotificationReceiver<'a> {
132+
pub struct ChannelNotificationReceiver<'a> {
133133
channel: &'a mut CloseOnDrop<lapin::Channel>,
134134
deliver: &'a Delivery,
135135
}
136136

137+
impl<'a> ChannelNotificationReceiver<'a> {
138+
pub fn new(channel: &'a mut CloseOnDrop<lapin::Channel>, deliver: &'a Delivery) -> Self {
139+
ChannelNotificationReceiver { channel, deliver }
140+
}
141+
}
142+
137143
impl<'a> NotificationReceiver for ChannelNotificationReceiver<'a> {
138144
fn tell(&mut self, action: Action) {
139145
task::block_on(action_deliver(self.channel, self.deliver, action))

0 commit comments

Comments
 (0)