Skip to content

Commit

Permalink
feat: Add cron-mon CLI command for creating new monitors (#85)
Browse files Browse the repository at this point in the history
* feat: Add `cron-mon` CLI command for creating new monitors

* chore: Ignore binaries in code coverage
  • Loading branch information
howamith authored Nov 26, 2024
1 parent ab3393d commit 0c241ea
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test-coverage:
cargo llvm-cov \
--no-clean \
--show-missing-lines \
--ignore-filename-regex="src/infrastructure/db_schema.rs" \
--ignore-filename-regex="src/bin|src/infrastructure/db_schema.rs" \
--fail-under-lines=95 \
--jobs=3 \
--lcov \
Expand Down
34 changes: 33 additions & 1 deletion api/src/bin/cron_mon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use std::sync::Arc;

use clap::{Args, Parser, Subcommand};

use cron_mon_api::application::services::get_process_late_jobs_service;
use cron_mon_api::application::services::{
get_create_monitor_service, get_process_late_jobs_service,
};
use cron_mon_api::infrastructure::database::create_connection_pool;
use cron_mon_api::infrastructure::logging::init_logging;

Expand All @@ -26,6 +28,9 @@ enum Command {

/// Run the monitor.
Monitor(MonitorArgs),

/// Create a new monitor.
CreateMonitor(CreateMonitorArgs),
}

#[derive(Args)]
Expand All @@ -35,6 +40,25 @@ struct MonitorArgs {
interval: u64,
}

#[derive(Args)]
struct CreateMonitorArgs {
/// The name of the monitor.
#[arg(short, long)]
name: String,

/// The expected duration of jobs monitored by this monitor, in seconds.
#[arg(short, long)]
expected: i32,

/// The grace duration for jobs monitored by this monitor, in seconds.
#[arg(short, long)]
grace: i32,

/// The tenant that the monitor is to belong to.
#[arg(short, long)]
tenant: String,
}

#[tokio::main]
async fn main() {
init_logging();
Expand All @@ -59,6 +83,14 @@ async fn main() {
})
.await;
}
Command::CreateMonitor(args) => {
let pool = create_connection_pool().expect("Failed to create DB connection pool.");
let mut service = get_create_monitor_service(&pool);
service
.create_by_attributes(&args.tenant, &args.name, args.expected, args.grace)
.await
.expect("Failed to create monitor.");
}
}
}

Expand Down

0 comments on commit 0c241ea

Please sign in to comment.