Device as Parameter

This commit is contained in:
Dimitrios Kouros
2026-08-03 16:50:21 +03:00
parent c36bcb4275
commit e0848d607d
+7 -4
View File
@@ -12,15 +12,18 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let db = Db::from_env();
let email_service = EmailService::from_env();
let device_name = "Pixel 10";
let device_name = std::env::args()
.nth(1)
.or_else(|| std::env::var("DEVICE_NAME").ok())
.unwrap_or_else(|| "Pixel 10".to_string());
let token = match db.get_token_by_device(device_name).await? {
let token = match db.get_token_by_device(&device_name).await? {
Some(token) => token,
None => {
let err_msg = format!("Device '{}' not found in database", device_name);
eprintln!("{}", err_msg);
if let Some(es) = &email_service {
if let Err(e) = es.send_fcm_failure_alert(device_name, &err_msg).await {
if let Err(e) = es.send_fcm_failure_alert(&device_name, &err_msg).await {
eprintln!("Failed to send alert email: {}", e);
}
}
@@ -43,7 +46,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
if let Err(err) = service.send_notification(message).await {
eprintln!("FCM notification failed: {}", err);
if let Some(es) = &email_service {
if let Err(e) = es.send_fcm_failure_alert(device_name, &err.to_string()).await {
if let Err(e) = es.send_fcm_failure_alert(&device_name, &err.to_string()).await {
eprintln!("Failed to send alert email: {}", e);
}
}