Merge pull request #495 from LnL7/lapin-log-message-collector
convert log-message-collector to easylapin
This commit is contained in:
commit
5e48f5f019
|
@ -56,7 +56,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
no_wait: false,
|
no_wait: false,
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let handle = chan.consume(
|
let handle = easylapin::WorkerChannel(chan).consume(
|
||||||
tasks::evaluationfilter::EvaluationFilterWorker::new(cfg.acl()),
|
tasks::evaluationfilter::EvaluationFilterWorker::new(cfg.acl()),
|
||||||
easyamqp::ConsumeConfig {
|
easyamqp::ConsumeConfig {
|
||||||
queue: queue_name.clone(),
|
queue: queue_name.clone(),
|
||||||
|
|
|
@ -57,7 +57,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
no_wait: false,
|
no_wait: false,
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let handle = chan.consume(
|
let handle = easylapin::WorkerChannel(chan).consume(
|
||||||
tasks::githubcommentfilter::GitHubCommentWorker::new(cfg.acl(), cfg.github()),
|
tasks::githubcommentfilter::GitHubCommentWorker::new(cfg.acl(), cfg.github()),
|
||||||
easyamqp::ConsumeConfig {
|
easyamqp::ConsumeConfig {
|
||||||
queue: "build-inputs".to_owned(),
|
queue: "build-inputs".to_owned(),
|
||||||
|
|
|
@ -46,7 +46,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
no_wait: false,
|
no_wait: false,
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let handle = chan.consume(
|
let handle = easylapin::WorkerChannel(chan).consume(
|
||||||
tasks::githubcommentposter::GitHubCommentPoster::new(cfg.github_app_vendingmachine()),
|
tasks::githubcommentposter::GitHubCommentPoster::new(cfg.github_app_vendingmachine()),
|
||||||
easyamqp::ConsumeConfig {
|
easyamqp::ConsumeConfig {
|
||||||
queue: "build-results".to_owned(),
|
queue: "build-results".to_owned(),
|
||||||
|
|
|
@ -1,24 +1,27 @@
|
||||||
use ofborg::config;
|
|
||||||
use ofborg::easyamqp::{self, ChannelExt, ConsumerExt};
|
|
||||||
use ofborg::tasks;
|
|
||||||
use ofborg::worker;
|
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::error::Error;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use async_std::task;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
fn main() {
|
use ofborg::config;
|
||||||
let cfg = config::load(env::args().nth(1).unwrap().as_ref());
|
use ofborg::easyamqp::{self, ChannelExt, ConsumerExt};
|
||||||
|
use ofborg::easylapin;
|
||||||
|
use ofborg::tasks;
|
||||||
|
|
||||||
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
ofborg::setup_log();
|
ofborg::setup_log();
|
||||||
|
|
||||||
let mut session = easyamqp::session_from_config(&cfg.rabbitmq).unwrap();
|
let arg = env::args()
|
||||||
info!("Connected to rabbitmq");
|
.nth(1)
|
||||||
|
.expect("usage: log-message-collector <config>");
|
||||||
|
let cfg = config::load(arg.as_ref());
|
||||||
|
|
||||||
let mut channel = session.open_channel(1).unwrap();
|
let conn = easylapin::from_config(&cfg.rabbitmq)?;
|
||||||
|
let mut chan = task::block_on(conn.create_channel())?;
|
||||||
|
|
||||||
channel
|
chan.declare_exchange(easyamqp::ExchangeConfig {
|
||||||
.declare_exchange(easyamqp::ExchangeConfig {
|
|
||||||
exchange: "logs".to_owned(),
|
exchange: "logs".to_owned(),
|
||||||
exchange_type: easyamqp::ExchangeType::Topic,
|
exchange_type: easyamqp::ExchangeType::Topic,
|
||||||
passive: false,
|
passive: false,
|
||||||
|
@ -26,53 +29,45 @@ fn main() {
|
||||||
auto_delete: false,
|
auto_delete: false,
|
||||||
no_wait: false,
|
no_wait: false,
|
||||||
internal: false,
|
internal: false,
|
||||||
})
|
})?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let queue_name = "".to_owned();
|
let queue_name = "".to_owned();
|
||||||
channel
|
chan.declare_queue(easyamqp::QueueConfig {
|
||||||
.declare_queue(easyamqp::QueueConfig {
|
|
||||||
queue: queue_name.clone(),
|
queue: queue_name.clone(),
|
||||||
passive: false,
|
passive: false,
|
||||||
durable: false,
|
durable: false,
|
||||||
exclusive: true,
|
exclusive: true,
|
||||||
auto_delete: true,
|
auto_delete: true,
|
||||||
no_wait: false,
|
no_wait: false,
|
||||||
})
|
})?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
channel
|
chan.bind_queue(easyamqp::BindQueueConfig {
|
||||||
.bind_queue(easyamqp::BindQueueConfig {
|
|
||||||
queue: queue_name.clone(),
|
queue: queue_name.clone(),
|
||||||
exchange: "logs".to_owned(),
|
exchange: "logs".to_owned(),
|
||||||
routing_key: Some("*.*".to_owned()),
|
routing_key: Some("*.*".to_owned()),
|
||||||
no_wait: false,
|
no_wait: false,
|
||||||
})
|
})?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut channel = channel
|
// Regular channel, we want prefetching here.
|
||||||
.consume(
|
let handle = chan.consume(
|
||||||
worker::new(tasks::log_message_collector::LogMessageCollector::new(
|
tasks::log_message_collector::LogMessageCollector::new(
|
||||||
PathBuf::from(cfg.log_storage.clone().unwrap().path),
|
PathBuf::from(cfg.log_storage.clone().unwrap().path),
|
||||||
100,
|
100,
|
||||||
)),
|
),
|
||||||
easyamqp::ConsumeConfig {
|
easyamqp::ConsumeConfig {
|
||||||
queue: queue_name,
|
queue: queue_name.clone(),
|
||||||
consumer_tag: format!("{}-log-collector", cfg.whoami()),
|
consumer_tag: format!("{}-log-collector", cfg.whoami()),
|
||||||
no_local: false,
|
no_local: false,
|
||||||
no_ack: false,
|
no_ack: false,
|
||||||
no_wait: false,
|
no_wait: false,
|
||||||
exclusive: false,
|
exclusive: false,
|
||||||
},
|
},
|
||||||
)
|
)?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
channel.start_consuming();
|
info!("Fetching jobs from {}", &queue_name);
|
||||||
|
task::block_on(handle);
|
||||||
|
|
||||||
info!("Finished consuming?");
|
drop(conn); // Close connection.
|
||||||
|
|
||||||
channel.close(200, "Bye").unwrap();
|
|
||||||
info!("Closed the channel");
|
|
||||||
session.close(200, "Good Bye");
|
|
||||||
info!("Closed the session... EOF");
|
info!("Closed the session... EOF");
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
no_wait: false,
|
no_wait: false,
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let handle = chan.consume(
|
let handle = easylapin::WorkerChannel(chan).consume(
|
||||||
tasks::evaluate::EvaluationWorker::new(
|
tasks::evaluate::EvaluationWorker::new(
|
||||||
cloner,
|
cloner,
|
||||||
&nix,
|
&nix,
|
||||||
|
|
|
@ -86,8 +86,6 @@ impl<'a, W: SimpleWorker + 'a> ConsumerExt<'a, W> for CloseOnDrop<Channel> {
|
||||||
type Handle = Pin<Box<dyn Future<Output = ()> + 'a>>;
|
type Handle = Pin<Box<dyn Future<Output = ()> + 'a>>;
|
||||||
|
|
||||||
fn consume(self, mut worker: W, config: ConsumeConfig) -> Result<Self::Handle, Self::Error> {
|
fn consume(self, mut worker: W, config: ConsumeConfig) -> Result<Self::Handle, Self::Error> {
|
||||||
task::block_on(self.basic_qos(1, BasicQosOptions::default()))?;
|
|
||||||
|
|
||||||
let mut consumer = task::block_on(self.basic_consume(
|
let mut consumer = task::block_on(self.basic_consume(
|
||||||
&config.queue,
|
&config.queue,
|
||||||
&config.consumer_tag,
|
&config.consumer_tag,
|
||||||
|
@ -117,6 +115,20 @@ impl<'a, W: SimpleWorker + 'a> ConsumerExt<'a, W> for CloseOnDrop<Channel> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Same as a regular channel, but without prefetching,
|
||||||
|
/// used for services with multiple instances.
|
||||||
|
pub struct WorkerChannel(pub CloseOnDrop<Channel>);
|
||||||
|
|
||||||
|
impl<'a, W: SimpleWorker + 'a> ConsumerExt<'a, W> for WorkerChannel {
|
||||||
|
type Error = lapin::Error;
|
||||||
|
type Handle = Pin<Box<dyn Future<Output = ()> + 'a>>;
|
||||||
|
|
||||||
|
fn consume(self, worker: W, config: ConsumeConfig) -> Result<Self::Handle, Self::Error> {
|
||||||
|
task::block_on(self.0.basic_qos(1, BasicQosOptions::default()))?;
|
||||||
|
self.0.consume(worker, config)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct ChannelNotificationReceiver<'a> {
|
struct ChannelNotificationReceiver<'a> {
|
||||||
channel: &'a mut CloseOnDrop<lapin::Channel>,
|
channel: &'a mut CloseOnDrop<lapin::Channel>,
|
||||||
deliver: &'a Delivery,
|
deliver: &'a Delivery,
|
||||||
|
|
Loading…
Reference in a new issue