send mails on program exit
This commit is contained in:
parent
71c971a6e6
commit
98cb1d875c
12
src/main.rs
12
src/main.rs
@ -5,6 +5,7 @@ use std::{
|
|||||||
fs::{self, File},
|
fs::{self, File},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
process::exit,
|
process::exit,
|
||||||
|
sync::{Arc, Mutex},
|
||||||
thread,
|
thread,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -23,8 +24,8 @@ mod utils;
|
|||||||
|
|
||||||
use crate::output::{player, write_hls};
|
use crate::output::{player, write_hls};
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
generate_playlist, init_logging, validate_ffmpeg, GlobalConfig, PlayerControl, PlayoutStatus,
|
generate_playlist, init_logging, send_mail, validate_ffmpeg, GlobalConfig, PlayerControl,
|
||||||
ProcessControl,
|
PlayoutStatus, ProcessControl,
|
||||||
};
|
};
|
||||||
use rpc::json_rpc_server;
|
use rpc::json_rpc_server;
|
||||||
|
|
||||||
@ -70,8 +71,9 @@ fn main() {
|
|||||||
let play_control = PlayerControl::new();
|
let play_control = PlayerControl::new();
|
||||||
let playout_stat = PlayoutStatus::new();
|
let playout_stat = PlayoutStatus::new();
|
||||||
let proc_control = ProcessControl::new();
|
let proc_control = ProcessControl::new();
|
||||||
|
let messages = Arc::new(Mutex::new(Vec::new()));
|
||||||
|
|
||||||
let logging = init_logging(&config);
|
let logging = init_logging(&config, messages.clone());
|
||||||
CombinedLogger::init(logging).unwrap();
|
CombinedLogger::init(logging).unwrap();
|
||||||
|
|
||||||
validate_ffmpeg(&config);
|
validate_ffmpeg(&config);
|
||||||
@ -101,5 +103,9 @@ fn main() {
|
|||||||
player(&config, play_control, playout_stat, proc_control);
|
player(&config, play_control, playout_stat, proc_control);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if messages.lock().unwrap().len() > 0 {
|
||||||
|
send_mail(&config, messages.lock().unwrap().join("\n"));
|
||||||
|
}
|
||||||
|
|
||||||
info!("Playout done...");
|
info!("Playout done...");
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
|
sync::{Arc, Mutex},
|
||||||
thread::{self, sleep},
|
thread::{self, sleep},
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
@ -27,13 +28,14 @@ fn playlist_change_at_midnight() {
|
|||||||
config.playlist.day_start = "00:00:00".into();
|
config.playlist.day_start = "00:00:00".into();
|
||||||
config.playlist.length = "24:00:00".into();
|
config.playlist.length = "24:00:00".into();
|
||||||
config.logging.log_to_file = false;
|
config.logging.log_to_file = false;
|
||||||
|
let messages = Arc::new(Mutex::new(Vec::new()));
|
||||||
|
|
||||||
let play_control = PlayerControl::new();
|
let play_control = PlayerControl::new();
|
||||||
let playout_stat = PlayoutStatus::new();
|
let playout_stat = PlayoutStatus::new();
|
||||||
let proc_control = ProcessControl::new();
|
let proc_control = ProcessControl::new();
|
||||||
let proc_ctl = proc_control.clone();
|
let proc_ctl = proc_control.clone();
|
||||||
|
|
||||||
let logging = init_logging(&config);
|
let logging = init_logging(&config, messages);
|
||||||
CombinedLogger::init(logging).unwrap();
|
CombinedLogger::init(logging).unwrap();
|
||||||
|
|
||||||
mock_time::set_mock_time("2022-05-09T23:59:45");
|
mock_time::set_mock_time("2022-05-09T23:59:45");
|
||||||
@ -52,13 +54,14 @@ fn playlist_change_at_six() {
|
|||||||
config.playlist.day_start = "06:00:00".into();
|
config.playlist.day_start = "06:00:00".into();
|
||||||
config.playlist.length = "24:00:00".into();
|
config.playlist.length = "24:00:00".into();
|
||||||
config.logging.log_to_file = false;
|
config.logging.log_to_file = false;
|
||||||
|
let messages = Arc::new(Mutex::new(Vec::new()));
|
||||||
|
|
||||||
let play_control = PlayerControl::new();
|
let play_control = PlayerControl::new();
|
||||||
let playout_stat = PlayoutStatus::new();
|
let playout_stat = PlayoutStatus::new();
|
||||||
let proc_control = ProcessControl::new();
|
let proc_control = ProcessControl::new();
|
||||||
let proc_ctl = proc_control.clone();
|
let proc_ctl = proc_control.clone();
|
||||||
|
|
||||||
let logging = init_logging(&config);
|
let logging = init_logging(&config, messages);
|
||||||
CombinedLogger::init(logging).unwrap();
|
CombinedLogger::init(logging).unwrap();
|
||||||
|
|
||||||
mock_time::set_mock_time("2022-05-09T05:59:45");
|
mock_time::set_mock_time("2022-05-09T05:59:45");
|
||||||
|
@ -25,7 +25,7 @@ use simplelog::*;
|
|||||||
use crate::utils::GlobalConfig;
|
use crate::utils::GlobalConfig;
|
||||||
|
|
||||||
/// send log messages to mail recipient
|
/// send log messages to mail recipient
|
||||||
fn send_mail(cfg: &GlobalConfig, msg: String) {
|
pub fn send_mail(cfg: &GlobalConfig, msg: String) {
|
||||||
if let Ok(email) = Message::builder()
|
if let Ok(email) = Message::builder()
|
||||||
.from(cfg.mail.sender_addr.parse().unwrap())
|
.from(cfg.mail.sender_addr.parse().unwrap())
|
||||||
.to(cfg.mail.recipient.parse().unwrap())
|
.to(cfg.mail.recipient.parse().unwrap())
|
||||||
@ -138,7 +138,10 @@ fn clean_string(text: &str) -> String {
|
|||||||
/// - console logger
|
/// - console logger
|
||||||
/// - file logger
|
/// - file logger
|
||||||
/// - mail logger
|
/// - mail logger
|
||||||
pub fn init_logging(config: &GlobalConfig) -> Vec<Box<dyn SharedLogger>> {
|
pub fn init_logging(
|
||||||
|
config: &GlobalConfig,
|
||||||
|
messages: Arc<Mutex<Vec<String>>>,
|
||||||
|
) -> Vec<Box<dyn SharedLogger>> {
|
||||||
let config_clone = config.clone();
|
let config_clone = config.clone();
|
||||||
let app_config = config.logging.clone();
|
let app_config = config.logging.clone();
|
||||||
let mut time_level = LevelFilter::Off;
|
let mut time_level = LevelFilter::Off;
|
||||||
@ -216,7 +219,6 @@ pub fn init_logging(config: &GlobalConfig) -> Vec<Box<dyn SharedLogger>> {
|
|||||||
|
|
||||||
// set mail logger only the recipient is set in config
|
// set mail logger only the recipient is set in config
|
||||||
if config.mail.recipient.contains('@') && config.mail.recipient.contains('.') {
|
if config.mail.recipient.contains('@') && config.mail.recipient.contains('.') {
|
||||||
let messages: Arc<Mutex<Vec<String>>> = Arc::new(Mutex::new(Vec::new()));
|
|
||||||
let messages_clone = messages.clone();
|
let messages_clone = messages.clone();
|
||||||
let interval = config.mail.interval;
|
let interval = config.mail.interval;
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ pub use controller::{PlayerControl, PlayoutStatus, ProcessControl, ProcessUnit::
|
|||||||
pub use generator::generate_playlist;
|
pub use generator::generate_playlist;
|
||||||
pub use json_serializer::{read_json, Playlist, DUMMY_LEN};
|
pub use json_serializer::{read_json, Playlist, DUMMY_LEN};
|
||||||
pub use json_validate::validate_playlist;
|
pub use json_validate::validate_playlist;
|
||||||
pub use logging::init_logging;
|
pub use logging::{init_logging, send_mail};
|
||||||
|
|
||||||
use crate::filter::filter_chains;
|
use crate::filter::filter_chains;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user