summaryrefslogtreecommitdiff
path: root/ofborg/tickborg/src/bin/github-comment-poster.rs
blob: 5c45d8f5464c7e47c672d4b5b9d5820c862c4f3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use std::env;
use std::error::Error;

use tracing::{error, info};

use tickborg::config;
use tickborg::easyamqp::{self, ChannelExt, ConsumerExt};
use tickborg::easylapin;
use tickborg::tasks;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    tickborg::setup_log();

    let arg = env::args()
        .nth(1)
        .unwrap_or_else(|| panic!("usage: {} <config>", std::env::args().next().unwrap()));
    let cfg = config::load(arg.as_ref());

    let Some(poster_cfg) = config::load(arg.as_ref()).github_comment_poster else {
        error!("No comment poster configuration found!");
        panic!();
    };

    let conn = easylapin::from_config(&poster_cfg.rabbitmq).await?;
    let mut chan = conn.create_channel().await?;

    chan.declare_exchange(easyamqp::ExchangeConfig {
        exchange: "build-results".to_owned(),
        exchange_type: easyamqp::ExchangeType::Fanout,
        passive: false,
        durable: true,
        auto_delete: false,
        no_wait: false,
        internal: false,
    })
    .await?;

    chan.declare_queue(easyamqp::QueueConfig {
        queue: "build-results".to_owned(),
        passive: false,
        durable: true,
        exclusive: false,
        auto_delete: false,
        no_wait: false,
    })
    .await?;

    chan.bind_queue(easyamqp::BindQueueConfig {
        queue: "build-results".to_owned(),
        exchange: "build-results".to_owned(),
        routing_key: None,
        no_wait: false,
    })
    .await?;

    let handle = easylapin::WorkerChannel(chan)
        .consume(
            tasks::githubcommentposter::GitHubCommentPoster::new(cfg.github_app_vendingmachine()),
            easyamqp::ConsumeConfig {
                queue: "build-results".to_owned(),
                consumer_tag: format!("{}-github-comment-poster", cfg.whoami()),
                no_local: false,
                no_ack: false,
                no_wait: false,
                exclusive: false,
            },
        )
        .await?;

    handle.await;

    drop(conn); // Close connection.
    info!("Closed the session... EOF");
    Ok(())
}