mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 12:56:30 +03:00
simplify double-fetching
This commit is contained in:
@@ -431,7 +431,7 @@ class TestOnlineAccount:
|
|||||||
ev = ac1._evlogger.get_matching("DC_EVENT_DELETED_BLOB_FILE")
|
ev = ac1._evlogger.get_matching("DC_EVENT_DELETED_BLOB_FILE")
|
||||||
|
|
||||||
def test_mvbox_sentbox_threads(self, acfactory, lp):
|
def test_mvbox_sentbox_threads(self, acfactory, lp):
|
||||||
lp.sec("ac1: start with mvbox/sentbox threads")
|
lp.sec("ac1: start with mvbox thread")
|
||||||
ac1 = acfactory.get_online_configuring_account(mvbox=True, sentbox=True)
|
ac1 = acfactory.get_online_configuring_account(mvbox=True, sentbox=True)
|
||||||
|
|
||||||
lp.sec("ac2: start without mvbox/sentbox threads")
|
lp.sec("ac2: start without mvbox/sentbox threads")
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ def test_dc_close_events(tmpdir):
|
|||||||
else:
|
else:
|
||||||
print("skipping event", *ev)
|
print("skipping event", *ev)
|
||||||
|
|
||||||
find("disconnecting INBOX-watch")
|
find("disconnecting inbox-thread")
|
||||||
find("disconnecting sentbox-thread")
|
find("disconnecting sentbox-thread")
|
||||||
find("disconnecting mvbox-thread")
|
find("disconnecting mvbox-thread")
|
||||||
find("disconnecting SMTP")
|
find("disconnecting SMTP")
|
||||||
|
|||||||
@@ -866,7 +866,8 @@ impl Imap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn fake_idle(&self, context: &Context, watch_folder: Option<String>) {
|
pub(crate) fn fake_idle(&self, context: &Context, watch_folder: Option<String>) {
|
||||||
// Idle using polling.
|
// Idle using polling. This is also needed if we're not yet configured -
|
||||||
|
// in this case, we're waiting for a configure job (and an interrupt).
|
||||||
task::block_on(async move {
|
task::block_on(async move {
|
||||||
let fake_idle_start_time = SystemTime::now();
|
let fake_idle_start_time = SystemTime::now();
|
||||||
|
|
||||||
@@ -1072,7 +1073,8 @@ impl Imap {
|
|||||||
task::block_on(async move {
|
task::block_on(async move {
|
||||||
if uid == 0 {
|
if uid == 0 {
|
||||||
return Some(ImapActionResult::Failed);
|
return Some(ImapActionResult::Failed);
|
||||||
} else if !self.is_connected().await {
|
}
|
||||||
|
if !self.is_connected().await {
|
||||||
// currently jobs are only performed on the INBOX thread
|
// currently jobs are only performed on the INBOX thread
|
||||||
// TODO: make INBOX/SENT/MVBOX perform the jobs on their
|
// TODO: make INBOX/SENT/MVBOX perform the jobs on their
|
||||||
// respective folders to avoid select_folder network traffic
|
// respective folders to avoid select_folder network traffic
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::sync::{Arc, Condvar, Mutex};
|
use std::sync::{Arc, Condvar, Mutex};
|
||||||
|
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::error::Error;
|
use crate::error::{Error, Result};
|
||||||
use crate::imap::Imap;
|
use crate::imap::Imap;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -85,48 +85,37 @@ impl JobThread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if use_network {
|
if use_network {
|
||||||
let prefix = format!("{}-fetch", self.name);
|
if let Err(err) = self.connect_and_fetch(context) {
|
||||||
match self.imap.connect_configured(context) {
|
warn!(context, "connect+fetch failed: {}, reconnect & retry", err);
|
||||||
Ok(()) => {
|
self.imap.trigger_reconnect();
|
||||||
if let Some(watch_folder) = self.get_watch_folder(context) {
|
if let Err(err) = self.connect_and_fetch(context) {
|
||||||
let start = std::time::Instant::now();
|
warn!(context, "connect+fetch failed: {}", err);
|
||||||
info!(context, "{} started...", prefix);
|
|
||||||
let res = self.imap.fetch(context, &watch_folder);
|
|
||||||
info!(
|
|
||||||
context,
|
|
||||||
"{} done in {:.3} ms.",
|
|
||||||
prefix,
|
|
||||||
start.elapsed().as_millis(),
|
|
||||||
);
|
|
||||||
|
|
||||||
if let Err(err) = res {
|
|
||||||
warn!(context, "fetch failed: {}, reconnect & retry", err);
|
|
||||||
self.imap.trigger_reconnect();
|
|
||||||
match self.imap.connect_configured(context) {
|
|
||||||
Ok(()) => {
|
|
||||||
if let Err(err) = self.imap.fetch(context, &watch_folder) {
|
|
||||||
error!(context, "fetch failed: {}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
error!(context, "connect failed: {}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
warn!(
|
|
||||||
context,
|
|
||||||
"{} skipped, could not connect to imap {:?}", prefix, err
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.state.0.lock().unwrap().using_handle = false;
|
self.state.0.lock().unwrap().using_handle = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn connect_and_fetch(&mut self, context: &Context) -> Result<()> {
|
||||||
|
let prefix = format!("{}-fetch", self.name);
|
||||||
|
match self.imap.connect_configured(context) {
|
||||||
|
Ok(()) => {
|
||||||
|
if let Some(watch_folder) = self.get_watch_folder(context) {
|
||||||
|
let start = std::time::Instant::now();
|
||||||
|
info!(context, "{} started...", prefix);
|
||||||
|
let res = self.imap.fetch(context, &watch_folder);
|
||||||
|
let elapsed = start.elapsed().as_millis();
|
||||||
|
info!(context, "{} done in {:.3} ms.", prefix, elapsed);
|
||||||
|
|
||||||
|
res
|
||||||
|
} else {
|
||||||
|
Err(Error::WatchFolderNotFound("not-set".to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn get_watch_folder(&self, context: &Context) -> Option<String> {
|
fn get_watch_folder(&self, context: &Context) -> Option<String> {
|
||||||
match context.sql.get_raw_config(context, self.folder_config_name) {
|
match context.sql.get_raw_config(context, self.folder_config_name) {
|
||||||
Some(name) => Some(name),
|
Some(name) => Some(name),
|
||||||
@@ -201,7 +190,6 @@ impl JobThread {
|
|||||||
// if the connection fails, use fake_idle to retry periodically
|
// if the connection fails, use fake_idle to retry periodically
|
||||||
// fake_idle() will be woken up by interrupt_idle() as
|
// fake_idle() will be woken up by interrupt_idle() as
|
||||||
// well so will act on maybe_network events
|
// well so will act on maybe_network events
|
||||||
//
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user