summaryrefslogtreecommitdiff
path: root/ofborg/tickborg/src/bin/mass-rebuilder.rs
blob: 0d5fdb01270f156f9654dc8d8154327172de7efb (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
use std::env;
use std::error::Error;
use std::path::Path;

use tracing::{error, info};

use tickborg::checkout;
use tickborg::config;
use tickborg::easyamqp::{self, ChannelExt, ConsumerExt};
use tickborg::easylapin;
use tickborg::stats;
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(rebuilder_cfg) = config::load(arg.as_ref()).mass_rebuilder else {
        error!("No mass rebuilder configuration found!");
        panic!();
    };

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

    let root = Path::new(&cfg.checkout.root);
    let cloner = checkout::cached_cloner(&root.join(cfg.runner.instance.to_string()));

    let events = stats::RabbitMq::from_lapin(&cfg.whoami(), conn.create_channel().await?);

    let queue_name = String::from("mass-rebuild-check-jobs");
    chan.declare_queue(easyamqp::QueueConfig {
        queue: queue_name.clone(),
        passive: false,
        durable: true,
        exclusive: false,
        auto_delete: false,
        no_wait: false,
    })
    .await?;

    let handle = easylapin::WorkerChannel(chan)
        .consume(
            tasks::evaluate::EvaluationWorker::new(
                cloner,
                cfg.github_app_vendingmachine(),
                cfg.acl(),
                cfg.runner.identity.clone(),
                events,
            ),
            easyamqp::ConsumeConfig {
                queue: queue_name.clone(),
                consumer_tag: format!("{}-mass-rebuild-checker", cfg.whoami()),
                no_local: false,
                no_ack: false,
                no_wait: false,
                exclusive: false,
            },
        )
        .await?;

    info!("Fetching jobs from {}", queue_name);
    handle.await;

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