Device as Parameter
This commit is contained in:
+7
-4
@@ -12,15 +12,18 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let db = Db::from_env();
|
let db = Db::from_env();
|
||||||
let email_service = EmailService::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,
|
Some(token) => token,
|
||||||
None => {
|
None => {
|
||||||
let err_msg = format!("Device '{}' not found in database", device_name);
|
let err_msg = format!("Device '{}' not found in database", device_name);
|
||||||
eprintln!("{}", err_msg);
|
eprintln!("{}", err_msg);
|
||||||
if let Some(es) = &email_service {
|
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);
|
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 {
|
if let Err(err) = service.send_notification(message).await {
|
||||||
eprintln!("FCM notification failed: {}", err);
|
eprintln!("FCM notification failed: {}", err);
|
||||||
if let Some(es) = &email_service {
|
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);
|
eprintln!("Failed to send alert email: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user