Merge pull request #484 from LnL7/lapin-comment-filter
lapin github-comment-filter
This commit is contained in:
commit
a918d73eef
|
@ -1,91 +1,78 @@
|
||||||
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 amqp::Basic;
|
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();
|
||||||
|
|
||||||
info!("Hello, world!");
|
let arg = env::args()
|
||||||
|
.nth(1)
|
||||||
|
.expect("usage: github-comment-filter <config>");
|
||||||
|
let cfg = config::load(arg.as_ref());
|
||||||
|
|
||||||
let mut session = easyamqp::session_from_config(&cfg.rabbitmq).unwrap();
|
let conn = easylapin::from_config(&cfg.rabbitmq)?;
|
||||||
info!("Connected to rabbitmq");
|
let mut chan = task::block_on(conn.create_channel())?;
|
||||||
|
|
||||||
let mut channel = session.open_channel(1).unwrap();
|
chan.declare_exchange(easyamqp::ExchangeConfig {
|
||||||
channel
|
exchange: "github-events".to_owned(),
|
||||||
.declare_exchange(easyamqp::ExchangeConfig {
|
exchange_type: easyamqp::ExchangeType::Topic,
|
||||||
exchange: "github-events".to_owned(),
|
passive: false,
|
||||||
exchange_type: easyamqp::ExchangeType::Topic,
|
durable: true,
|
||||||
passive: false,
|
auto_delete: false,
|
||||||
durable: true,
|
no_wait: false,
|
||||||
auto_delete: false,
|
internal: false,
|
||||||
no_wait: false,
|
})?;
|
||||||
internal: false,
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
channel
|
chan.declare_exchange(easyamqp::ExchangeConfig {
|
||||||
.declare_exchange(easyamqp::ExchangeConfig {
|
exchange: "build-jobs".to_owned(),
|
||||||
exchange: "build-jobs".to_owned(),
|
exchange_type: easyamqp::ExchangeType::Fanout,
|
||||||
exchange_type: easyamqp::ExchangeType::Fanout,
|
passive: false,
|
||||||
passive: false,
|
durable: true,
|
||||||
durable: true,
|
auto_delete: false,
|
||||||
auto_delete: false,
|
no_wait: false,
|
||||||
no_wait: false,
|
internal: false,
|
||||||
internal: false,
|
})?;
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
channel
|
let queue_name = "build-inputs";
|
||||||
.declare_queue(easyamqp::QueueConfig {
|
chan.declare_queue(easyamqp::QueueConfig {
|
||||||
|
queue: queue_name.to_owned(),
|
||||||
|
passive: false,
|
||||||
|
durable: true,
|
||||||
|
exclusive: false,
|
||||||
|
auto_delete: false,
|
||||||
|
no_wait: false,
|
||||||
|
})?;
|
||||||
|
|
||||||
|
chan.bind_queue(easyamqp::BindQueueConfig {
|
||||||
|
queue: "build-inputs".to_owned(),
|
||||||
|
exchange: "github-events".to_owned(),
|
||||||
|
routing_key: Some("issue_comment.*".to_owned()),
|
||||||
|
no_wait: false,
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let handle = chan.consume(
|
||||||
|
tasks::githubcommentfilter::GitHubCommentWorker::new(cfg.acl(), cfg.github()),
|
||||||
|
easyamqp::ConsumeConfig {
|
||||||
queue: "build-inputs".to_owned(),
|
queue: "build-inputs".to_owned(),
|
||||||
passive: false,
|
consumer_tag: format!("{}-github-comment-filter", cfg.whoami()),
|
||||||
durable: true,
|
no_local: false,
|
||||||
|
no_ack: false,
|
||||||
|
no_wait: false,
|
||||||
exclusive: false,
|
exclusive: false,
|
||||||
auto_delete: false,
|
},
|
||||||
no_wait: false,
|
)?;
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
channel
|
info!("Fetching jobs from {}", &queue_name);
|
||||||
.bind_queue(easyamqp::BindQueueConfig {
|
task::block_on(handle);
|
||||||
queue: "build-inputs".to_owned(),
|
|
||||||
exchange: "github-events".to_owned(),
|
|
||||||
routing_key: Some("issue_comment.*".to_owned()),
|
|
||||||
no_wait: false,
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
channel.basic_prefetch(1).unwrap();
|
drop(conn); // Close connection.
|
||||||
let mut channel = channel
|
|
||||||
.consume(
|
|
||||||
worker::new(tasks::githubcommentfilter::GitHubCommentWorker::new(
|
|
||||||
cfg.acl(),
|
|
||||||
cfg.github(),
|
|
||||||
)),
|
|
||||||
easyamqp::ConsumeConfig {
|
|
||||||
queue: "build-inputs".to_owned(),
|
|
||||||
consumer_tag: format!("{}-github-comment-filter", cfg.whoami()),
|
|
||||||
no_local: false,
|
|
||||||
no_ack: false,
|
|
||||||
no_wait: false,
|
|
||||||
exclusive: false,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
channel.start_consuming();
|
|
||||||
|
|
||||||
info!("Finished consuming?");
|
|
||||||
|
|
||||||
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(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::ghevent;
|
||||||
use crate::message::{buildjob, evaluationjob, Pr, Repo};
|
use crate::message::{buildjob, evaluationjob, Pr, Repo};
|
||||||
use crate::worker;
|
use crate::worker;
|
||||||
|
|
||||||
use tracing::{error, info};
|
use tracing::{debug_span, error, info};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub struct GitHubCommentWorker {
|
pub struct GitHubCommentWorker {
|
||||||
|
@ -34,7 +34,12 @@ impl worker::SimpleWorker for GitHubCommentWorker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: remove with rust/cargo update
|
||||||
|
#[allow(clippy::cognitive_complexity)]
|
||||||
fn consumer(&mut self, job: &ghevent::IssueComment) -> worker::Actions {
|
fn consumer(&mut self, job: &ghevent::IssueComment) -> worker::Actions {
|
||||||
|
let span = debug_span!("job", pr = ?job.issue.number);
|
||||||
|
let _enter = span.enter();
|
||||||
|
|
||||||
if job.action == ghevent::IssueCommentAction::Deleted {
|
if job.action == ghevent::IssueCommentAction::Deleted {
|
||||||
return vec![worker::Action::Ack];
|
return vec![worker::Action::Ack];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue