Retry push notifications on registration failure
This commit is contained in:
3 files changed
+30
-19
No files matched your search
Generated
-1
@@ -1697,7 +1697,6 @@ dependencies = [
|
||||
"md5",
|
||||
"neolink_core",
|
||||
"regex",
|
||||
"reqwest",
|
||||
"rumqttc",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
||||
@@ -32,7 +32,6 @@ log = { version = "0.4.17", features = [ "release_max_level_debug" ] }
|
||||
md5 = "0.7.0"
|
||||
neolink_core = { path = "crates/core", version = "0.6.2" }
|
||||
regex = "1.7.3"
|
||||
reqwest = "0.11.20"
|
||||
rumqttc = "0.22.0"
|
||||
serde = { version = "1.0.160", features = ["derive"] }
|
||||
serde_json = "1.0.96"
|
||||
|
||||
+30
-17
@@ -5,10 +5,13 @@
|
||||
|
||||
use fcm_push_listener::*;
|
||||
use std::{fs, sync::Arc};
|
||||
use tokio::sync::{
|
||||
mpsc::Receiver as MpscReceiver,
|
||||
oneshot::Sender as OneshotSender,
|
||||
watch::{channel as watch, Receiver as WatchReceiver, Sender as WatchSender},
|
||||
use tokio::{
|
||||
sync::{
|
||||
mpsc::Receiver as MpscReceiver,
|
||||
oneshot::Sender as OneshotSender,
|
||||
watch::{channel as watch, Receiver as WatchReceiver, Sender as WatchSender},
|
||||
},
|
||||
time::{sleep, Duration},
|
||||
};
|
||||
|
||||
use super::NeoInstance;
|
||||
@@ -47,6 +50,9 @@ impl PushNotiThread {
|
||||
pn_request_rx: &mut MpscReceiver<PnRequest>,
|
||||
) -> AnyResult<()> {
|
||||
loop {
|
||||
// Short wait on start/retry
|
||||
sleep(Duration::from_secs(3)).await;
|
||||
|
||||
let sender_id = "743639030586"; // andriod
|
||||
// let sender_id = "696841269229"; // ios
|
||||
|
||||
@@ -64,20 +70,27 @@ impl PushNotiThread {
|
||||
registration
|
||||
} else {
|
||||
log::debug!("Registering new push notification token");
|
||||
let registration = fcm_push_listener::register(sender_id).await?;
|
||||
let new_token = toml::to_string(®istration)?;
|
||||
if let Some(Err(e)) = token_path
|
||||
.as_ref()
|
||||
.map(|token_path| fs::write(token_path, &new_token))
|
||||
{
|
||||
log::warn!(
|
||||
"Unable to save push notification details ({}) to {:#?} because of the error {:#?}",
|
||||
new_token,
|
||||
token_path,
|
||||
e
|
||||
);
|
||||
match fcm_push_listener::register(sender_id).await {
|
||||
Ok(registration) => {
|
||||
let new_token = toml::to_string(®istration)?;
|
||||
if let Some(Err(e)) = token_path
|
||||
.as_ref()
|
||||
.map(|token_path| fs::write(token_path, &new_token))
|
||||
{
|
||||
log::warn!(
|
||||
"Unable to save push notification details ({}) to {:#?} because of the error {:#?}",
|
||||
new_token,
|
||||
token_path,
|
||||
e
|
||||
);
|
||||
}
|
||||
registration
|
||||
}
|
||||
Err(e) => {
|
||||
log::warn!("Issue connecting to push notifications server: {:?}", e);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
registration
|
||||
};
|
||||
|
||||
// Send registration.fcm_token to the server to allow it to send push messages to you.
|
||||
|
||||
Reference in new issue
Block a user