-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
77 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
/target/ | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[package] | ||
name = "daily-compprog" | ||
version = "0.1.0" | ||
edition = "2021" | ||
description = "My program! (TODO: Edit this description)" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
# General | ||
miette = "5" | ||
|
||
# Logging | ||
env_logger = "0.9" | ||
log = "0.4" | ||
|
||
# Tokio | ||
tokio = { version = "1", features = ["full"] } | ||
|
||
# Shutdown | ||
tokio-graceful-shutdown = "0.11.1" | ||
|
||
# Command line arguments | ||
clap = { version = "4.0", features = ["derive"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use clap::Parser; | ||
use env_logger::Env; | ||
|
||
#[derive(Parser)] | ||
#[clap(version, about, long_about = None)] | ||
pub struct Options { | ||
/// Increase verbosity, and can be used multiple times | ||
#[arg(short, long, action = clap::ArgAction::Count)] | ||
pub verbose: u8, | ||
} | ||
|
||
pub fn parse() -> Options { | ||
let opts = Options::parse(); | ||
|
||
let debug_level = match opts.verbose { | ||
0 => "info", | ||
1 => "debug", | ||
_ => "trace", | ||
}; | ||
env_logger::Builder::from_env(Env::default().default_filter_or(debug_level)).init(); | ||
|
||
opts | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use miette::Result; | ||
use tokio_graceful_shutdown::SubsystemHandle; | ||
|
||
pub async fn dummy_task(subsys: SubsystemHandle) -> Result<()> { | ||
log::info!("dummy_task started."); | ||
subsys.on_shutdown_requested().await; | ||
log::info!("dummy_task stopped"); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
mod command_line; | ||
mod dummy_task; | ||
|
||
use miette::Result; | ||
use tokio::time::Duration; | ||
use tokio_graceful_shutdown::Toplevel; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
// Query command line options and initialize logging | ||
let _opts = command_line::parse(); | ||
|
||
// Initialize and run subsystems | ||
Toplevel::new() | ||
.start("dummy_task", dummy_task::dummy_task) | ||
.catch_signals() | ||
.handle_shutdown_requests(Duration::from_millis(1000)) | ||
.await | ||
.map_err(Into::into) | ||
} |