feat: add a pastebin log collector
This will replace the Gist feature, a GitHub-only thing. Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
This commit is contained in:
parent
8406768fbb
commit
e365acc085
72
ofborg/src/bin/pastebin-web.rs
Normal file
72
ofborg/src/bin/pastebin-web.rs
Normal file
|
@ -0,0 +1,72 @@
|
|||
use std::env;
|
||||
use std::error::Error;
|
||||
|
||||
use async_std::task;
|
||||
use ofborg::config;
|
||||
use ofborg::easyamqp;
|
||||
use ofborg::easyamqp::ChannelExt;
|
||||
use ofborg::easyamqp::ConsumerExt;
|
||||
use ofborg::easylapin;
|
||||
use ofborg::tasks;
|
||||
use tracing::info;
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
ofborg::setup_log();
|
||||
|
||||
let arg = env::args().nth(1).expect("usage: pastebin-web <config>");
|
||||
let cfg = config::load(arg.as_ref());
|
||||
|
||||
let conn = easylapin::from_config(&cfg.rabbitmq)?;
|
||||
let mut chan = task::block_on(conn.create_channel())?;
|
||||
|
||||
let queue_name = "pastebin-log".to_owned();
|
||||
|
||||
chan.declare_exchange(easyamqp::ExchangeConfig {
|
||||
exchange: "pastebin-log".to_owned(),
|
||||
exchange_type: easyamqp::ExchangeType::Topic,
|
||||
passive: false,
|
||||
durable: true,
|
||||
auto_delete: false,
|
||||
no_wait: false,
|
||||
internal: false,
|
||||
})?;
|
||||
|
||||
chan.declare_queue(easyamqp::QueueConfig {
|
||||
queue: queue_name.clone(),
|
||||
passive: false,
|
||||
durable: true,
|
||||
exclusive: false,
|
||||
auto_delete: false,
|
||||
no_wait: false,
|
||||
})?;
|
||||
|
||||
chan.bind_queue(easyamqp::BindQueueConfig {
|
||||
queue: queue_name.clone(),
|
||||
exchange: "pastebin-log".to_owned(),
|
||||
routing_key: None,
|
||||
no_wait: false,
|
||||
})?;
|
||||
|
||||
let handle = easylapin::WorkerChannel(chan).consume(
|
||||
tasks::pastebin_collector::PastebinCollector::new(
|
||||
cfg.pastebin.clone().path
|
||||
),
|
||||
easyamqp::ConsumeConfig {
|
||||
queue: queue_name.clone(),
|
||||
consumer_tag: format!("{}-pastebin-web", cfg.whoami()),
|
||||
no_local: false,
|
||||
no_ack: false,
|
||||
no_wait: false,
|
||||
exclusive: false,
|
||||
},
|
||||
)?;
|
||||
|
||||
// Boot an HTTP server to serve pastebin logs as well.
|
||||
|
||||
info!("Fetching jobs from {}", &queue_name);
|
||||
task::block_on(handle);
|
||||
|
||||
drop(conn); // Close connection.
|
||||
info!("Closed the session... EOF");
|
||||
Ok(())
|
||||
}
|
|
@ -21,6 +21,7 @@ pub struct Config {
|
|||
pub rabbitmq: RabbitMqConfig,
|
||||
pub github: Option<GithubConfig>,
|
||||
pub github_app: Option<GithubAppConfig>,
|
||||
pub pastebin: PastebinConfig,
|
||||
pub log_storage: Option<LogStorage>,
|
||||
}
|
||||
|
||||
|
@ -29,6 +30,13 @@ pub struct FeedbackConfig {
|
|||
pub full_logs: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct PastebinConfig {
|
||||
pub path: PathBuf,
|
||||
// max_disk_size?
|
||||
// auto_expiry?
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct RabbitMqConfig {
|
||||
pub ssl: bool,
|
||||
|
|
|
@ -41,6 +41,7 @@ pub mod systems;
|
|||
pub mod tagger;
|
||||
pub mod tasks;
|
||||
pub mod test_scratch;
|
||||
pub mod utils;
|
||||
pub mod vcs;
|
||||
pub mod worker;
|
||||
pub mod writetoline;
|
||||
|
|
|
@ -4,5 +4,6 @@ pub mod evaluate;
|
|||
pub mod evaluationfilter;
|
||||
pub mod githubcommentfilter;
|
||||
pub mod githubcommentposter;
|
||||
pub mod pastebin_collector;
|
||||
pub mod log_message_collector;
|
||||
pub mod statscollector;
|
||||
|
|
46
ofborg/src/tasks/pastebin_collector.rs
Normal file
46
ofborg/src/tasks/pastebin_collector.rs
Normal file
|
@ -0,0 +1,46 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use crate::{utils::pastebin::Pastebin, worker};
|
||||
|
||||
enum CompressionMethod {
|
||||
//None,
|
||||
Zstd,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct PastebinCollector {
|
||||
pastebin_root: PathBuf,
|
||||
compression_method: CompressionMethod,
|
||||
}
|
||||
|
||||
impl PastebinCollector {
|
||||
pub fn new(pastebin_root: PathBuf) -> Self {
|
||||
Self {
|
||||
pastebin_root,
|
||||
compression_method: CompressionMethod::Zstd,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl worker::SimpleWorker for PastebinCollector {
|
||||
type J = Pastebin;
|
||||
|
||||
fn msg_to_job(
|
||||
&mut self,
|
||||
_routing_key: &str,
|
||||
_: &Option<String>,
|
||||
_body: &[u8],
|
||||
) -> Result<Self::J, String> {
|
||||
Ok(Pastebin {
|
||||
contents: "".to_owned(),
|
||||
})
|
||||
}
|
||||
|
||||
fn consumer(&mut self, _job: &Self::J) -> worker::Actions {
|
||||
// Persist the pastebin on disk compressed in the pastebin_root.
|
||||
vec![worker::Action::Ack]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {}
|
1
ofborg/src/utils/mod.rs
Normal file
1
ofborg/src/utils/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod pastebin;
|
4
ofborg/src/utils/pastebin.rs
Normal file
4
ofborg/src/utils/pastebin.rs
Normal file
|
@ -0,0 +1,4 @@
|
|||
// A micro-pastebin service.
|
||||
pub struct Pastebin {
|
||||
pub contents: String
|
||||
}
|
Loading…
Reference in a new issue