tell AnkiWeb to abort on interrupt

This commit is contained in:
Damien Elmes 2020-05-31 17:08:17 +10:00
parent 90e19daec2
commit d8b907e4e8
2 changed files with 13 additions and 3 deletions

View file

@ -33,8 +33,8 @@ use crate::{
sched::timespan::{answer_button_time, learning_congrats, studied_today, time_span}, sched::timespan::{answer_button_time, learning_congrats, studied_today, time_span},
search::SortMode, search::SortMode,
sync::{ sync::{
sync_login, FullSyncProgress, NormalSyncProgress, SyncActionRequired, SyncAuth, SyncOutput, sync_abort, sync_login, FullSyncProgress, NormalSyncProgress, SyncActionRequired, SyncAuth,
SyncStage, SyncOutput, SyncStage,
}, },
template::RenderedNode, template::RenderedNode,
text::{extract_av_tags, strip_av_tags, AVTag}, text::{extract_av_tags, strip_av_tags, AVTag},
@ -1258,6 +1258,7 @@ impl Backend {
self.sync_abort = Some(abort_handle); self.sync_abort = Some(abort_handle);
let mut rt = Runtime::new().unwrap(); let mut rt = Runtime::new().unwrap();
let input_copy = input.clone();
let ret = self.with_col(|col| { let ret = self.with_col(|col| {
let result = if check_only { let result = if check_only {
@ -1280,6 +1281,11 @@ impl Backend {
// if the user aborted, we'll need to clean up the transaction // if the user aborted, we'll need to clean up the transaction
if !check_only { if !check_only {
col.storage.rollback_trx()?; col.storage.rollback_trx()?;
// and tell AnkiWeb to clean up
let _handle = std::thread::spawn(move || {
let _ =
rt.block_on(sync_abort(input_copy.hkey, input_copy.host_number));
});
} }
Err(AnkiError::Interrupted) Err(AnkiError::Interrupted)

View file

@ -586,6 +586,11 @@ pub async fn sync_login(username: &str, password: &str) -> Result<SyncAuth> {
}) })
} }
pub async fn sync_abort(hkey: String, host_number: u32) -> Result<()> {
let remote = HTTPSyncClient::new(Some(hkey), host_number);
remote.abort().await
}
impl Collection { impl Collection {
pub async fn get_sync_status(&mut self, auth: SyncAuth) -> Result<SyncOutput> { pub async fn get_sync_status(&mut self, auth: SyncAuth) -> Result<SyncOutput> {
NormalSyncer::new(self, auth, |_p, _t| ()) NormalSyncer::new(self, auth, |_p, _t| ())
@ -598,7 +603,6 @@ impl Collection {
where where
F: FnMut(NormalSyncProgress, bool), F: FnMut(NormalSyncProgress, bool),
{ {
// fixme: server abort on failure
NormalSyncer::new(self, auth, progress_fn).sync().await NormalSyncer::new(self, auth, progress_fn).sync().await
} }