chore: stop retry when current plugin is going to destory (#495)
This commit is contained in:
parent
a045713222
commit
54dfeb5527
|
|
@ -1648,7 +1648,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "collab"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f8930ed1b19b65dd7b890df2b0db54048141e8c4#f8930ed1b19b65dd7b890df2b0db54048141e8c4"
|
||||
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=851239880d8aca9e07abb47d96a4f8ff532dd930#851239880d8aca9e07abb47d96a4f8ff532dd930"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
|
|
@ -1672,7 +1672,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "collab-document"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f8930ed1b19b65dd7b890df2b0db54048141e8c4#f8930ed1b19b65dd7b890df2b0db54048141e8c4"
|
||||
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=851239880d8aca9e07abb47d96a4f8ff532dd930#851239880d8aca9e07abb47d96a4f8ff532dd930"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"collab",
|
||||
|
|
@ -1691,7 +1691,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "collab-entity"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f8930ed1b19b65dd7b890df2b0db54048141e8c4#f8930ed1b19b65dd7b890df2b0db54048141e8c4"
|
||||
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=851239880d8aca9e07abb47d96a4f8ff532dd930#851239880d8aca9e07abb47d96a4f8ff532dd930"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bytes",
|
||||
|
|
@ -1706,7 +1706,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "collab-folder"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f8930ed1b19b65dd7b890df2b0db54048141e8c4#f8930ed1b19b65dd7b890df2b0db54048141e8c4"
|
||||
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=851239880d8aca9e07abb47d96a4f8ff532dd930#851239880d8aca9e07abb47d96a4f8ff532dd930"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
|
|
|
|||
|
|
@ -209,10 +209,10 @@ debug = true
|
|||
# will be removed when using yrs 0.18.2 that expose pendings
|
||||
yrs = { git = "https://github.com/appflowy/y-crdt", rev = "3f25bb510ca5274e7657d3713fbed41fb46b4487" }
|
||||
|
||||
collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f8930ed1b19b65dd7b890df2b0db54048141e8c4" }
|
||||
collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f8930ed1b19b65dd7b890df2b0db54048141e8c4" }
|
||||
collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f8930ed1b19b65dd7b890df2b0db54048141e8c4" }
|
||||
collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f8930ed1b19b65dd7b890df2b0db54048141e8c4" }
|
||||
collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "851239880d8aca9e07abb47d96a4f8ff532dd930" }
|
||||
collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "851239880d8aca9e07abb47d96a4f8ff532dd930" }
|
||||
collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "851239880d8aca9e07abb47d96a4f8ff532dd930" }
|
||||
collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "851239880d8aca9e07abb47d96a4f8ff532dd930" }
|
||||
|
||||
[features]
|
||||
ai_enable = []
|
||||
|
|
|
|||
|
|
@ -17,11 +17,12 @@ use futures_util::SinkExt;
|
|||
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::{Arc, Weak};
|
||||
use std::time::Duration;
|
||||
use tokio::time::sleep;
|
||||
use tokio_retry::strategy::FixedInterval;
|
||||
use tokio_retry::{Action, Retry};
|
||||
use tokio_retry::{Action, Condition, RetryIf};
|
||||
use tokio_stream::StreamExt;
|
||||
use tracing::{error, trace};
|
||||
use yrs::updates::encoder::Encode;
|
||||
|
|
@ -33,12 +34,18 @@ pub struct SyncPlugin<Sink, Stream, C> {
|
|||
#[allow(dead_code)]
|
||||
channel: Option<Arc<C>>,
|
||||
collab: Weak<MutexCollab>,
|
||||
is_destroyed: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
impl<Sink, Stream, C> Drop for SyncPlugin<Sink, Stream, C> {
|
||||
fn drop(&mut self) {
|
||||
#[cfg(feature = "sync_verbose_log")]
|
||||
trace!("Drop sync plugin: {}", self.object.object_id);
|
||||
|
||||
// when the plugin is dropped, set the is_destroyed flag to true
|
||||
self
|
||||
.is_destroyed
|
||||
.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -124,6 +131,7 @@ where
|
|||
object,
|
||||
channel,
|
||||
collab,
|
||||
is_destroyed: Arc::new(Default::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -143,8 +151,12 @@ where
|
|||
collab: self.collab.clone(),
|
||||
};
|
||||
|
||||
let condition = InitSyncRetryCondition {
|
||||
is_plugin_destroyed: self.is_destroyed.clone(),
|
||||
};
|
||||
|
||||
tokio::spawn(async move {
|
||||
if let Err(err) = Retry::spawn(retry_strategy, action).await {
|
||||
if let Err(err) = RetryIf::spawn(retry_strategy, action, condition).await {
|
||||
error!("Failed to start init sync: {}", err);
|
||||
}
|
||||
});
|
||||
|
|
@ -218,6 +230,12 @@ where
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn destroy(&self) {
|
||||
self
|
||||
.is_destroyed
|
||||
.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
@ -297,3 +315,15 @@ where
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct InitSyncRetryCondition {
|
||||
is_plugin_destroyed: Arc<AtomicBool>,
|
||||
}
|
||||
impl Condition<anyhow::Error> for InitSyncRetryCondition {
|
||||
fn should_retry(&mut self, _error: &anyhow::Error) -> bool {
|
||||
// Only retry if the plugin is not destroyed
|
||||
!self
|
||||
.is_plugin_destroyed
|
||||
.load(std::sync::atomic::Ordering::SeqCst)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ async fn get_user_default_workspace_test() {
|
|||
let test_client = TestClient::new_user().await;
|
||||
let folder = test_client.get_user_folder().await;
|
||||
|
||||
let views = folder.get_workspace_views();
|
||||
let views = folder.get_views_belong_to(&test_client.workspace_id().await);
|
||||
assert_eq!(views.len(), 1);
|
||||
assert_eq!(views[0].name, "Getting started");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue