print app version

This commit is contained in:
Aleksandr Trushkin
2021-01-11 01:03:53 +03:00
parent d19ea39f08
commit d5681018dd
6 changed files with 76 additions and 8 deletions

View File

@ -3,6 +3,9 @@ use envconfig::Envconfig;
use log::{debug, info, warn};
use teloxide::{prelude::*, utils::command::BotCommand};
const VERSION: &'static str = env!("GIT_REVISION");
const BRANCH: &'static str = env!("GIT_BRANCH");
#[tokio::main]
async fn main() {
debug!("starting the application");
@ -32,6 +35,7 @@ async fn run() {
env_logger::init();
let settings = Settings::init_from_env().expect("reading config values");
let startup = std::sync::Arc::from(std::time::SystemTime::now());
let bot = teloxide::Bot::builder()
.token(&settings.telegram_token)
@ -44,8 +48,10 @@ async fn run() {
let cmd: Vec<&str> = cmd.split(" ").collect();
let console_cmd = cmd.get(0).expect("getting console command").to_string();
let arg: String = cmd.get(1).unwrap_or_else(|| &"").to_string();
// let startup = std::sync::Arc::from(*startup);
let startup = *startup;
async move { handler(cx, command, climate, console_cmd, arg).await }
async move { handler(cx, command, climate, console_cmd, arg, startup).await }
})
.await;
}
@ -62,6 +68,7 @@ async fn handler(
dsn: String,
console_command: String,
console_arg: String,
startup: std::time::SystemTime,
) -> ResponseResult<()> {
let request_id = uuid::Uuid::new_v4();
@ -73,7 +80,10 @@ async fn handler(
match command {
Command::Help => cx.answer(Command::descriptions()).send().await?,
Command::HostTemperature => {
info!("querying command {} with arg {}", console_command, console_arg);
info!(
"querying command {} with arg {}",
console_command, console_arg
);
let cmd = std::process::Command::new(&console_command)
.arg(&console_arg)
@ -130,6 +140,15 @@ async fn handler(
))
.await?
}
Command::VersionRequest => {
cx.answer_str(format!(
"app version is {}@{}, uptime is {} second(-s)",
VERSION,
BRANCH,
startup.elapsed().unwrap().as_secs()
))
.await?
}
};
Ok(())
@ -144,4 +163,6 @@ enum Command {
RoomTemperature,
#[command(description = "temperature of raspberry.")]
HostTemperature,
#[command(description = "prints current version.")]
VersionRequest,
}