mirror of
https://github.com/chatmail/core.git
synced 2026-05-14 20:36:30 +03:00
make idle wait only as long as the next job wants to run
This commit is contained in:
@@ -491,7 +491,7 @@ pub fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::Error> {
|
|||||||
println!("{:#?}", context.get_info());
|
println!("{:#?}", context.get_info());
|
||||||
}
|
}
|
||||||
"interrupt" => {
|
"interrupt" => {
|
||||||
interrupt_inbox_idle(context, true);
|
interrupt_inbox_idle(context);
|
||||||
}
|
}
|
||||||
"maybenetwork" => {
|
"maybenetwork" => {
|
||||||
maybe_network(context);
|
maybe_network(context);
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ fn stop_threads(context: &Context) {
|
|||||||
println!("Stopping threads");
|
println!("Stopping threads");
|
||||||
IS_RUNNING.store(false, Ordering::Relaxed);
|
IS_RUNNING.store(false, Ordering::Relaxed);
|
||||||
|
|
||||||
interrupt_inbox_idle(context, true);
|
interrupt_inbox_idle(context);
|
||||||
interrupt_mvbox_idle(context);
|
interrupt_mvbox_idle(context);
|
||||||
interrupt_sentbox_idle(context);
|
interrupt_sentbox_idle(context);
|
||||||
interrupt_smtp_idle(context);
|
interrupt_smtp_idle(context);
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ fn main() {
|
|||||||
println!("stopping threads");
|
println!("stopping threads");
|
||||||
|
|
||||||
*running.write().unwrap() = false;
|
*running.write().unwrap() = false;
|
||||||
deltachat::job::interrupt_inbox_idle(&ctx, true);
|
deltachat::job::interrupt_inbox_idle(&ctx);
|
||||||
deltachat::job::interrupt_smtp_idle(&ctx);
|
deltachat::job::interrupt_smtp_idle(&ctx);
|
||||||
|
|
||||||
println!("joining");
|
println!("joining");
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use super::Imap;
|
|||||||
use async_imap::extensions::idle::IdleResponse;
|
use async_imap::extensions::idle::IdleResponse;
|
||||||
use async_std::prelude::*;
|
use async_std::prelude::*;
|
||||||
use async_std::task;
|
use async_std::task;
|
||||||
|
use core::cmp::min;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
|
|
||||||
@@ -45,7 +46,12 @@ impl Imap {
|
|||||||
task::block_on(async move { self.config.read().await.can_idle })
|
task::block_on(async move { self.config.read().await.can_idle })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn idle(&self, context: &Context, watch_folder: Option<String>) -> Result<()> {
|
pub fn idle(
|
||||||
|
&self,
|
||||||
|
context: &Context,
|
||||||
|
watch_folder: Option<String>,
|
||||||
|
timeout: Duration,
|
||||||
|
) -> Result<()> {
|
||||||
task::block_on(async move {
|
task::block_on(async move {
|
||||||
if !self.can_idle() {
|
if !self.can_idle() {
|
||||||
return Err(Error::IdleAbilityMissing);
|
return Err(Error::IdleAbilityMissing);
|
||||||
@@ -58,7 +64,7 @@ impl Imap {
|
|||||||
self.select_folder(context, watch_folder.clone()).await?;
|
self.select_folder(context, watch_folder.clone()).await?;
|
||||||
|
|
||||||
let session = self.session.lock().await.take();
|
let session = self.session.lock().await.take();
|
||||||
let timeout = Duration::from_secs(23 * 60);
|
let max_duration = Duration::from_secs(23 * 60);
|
||||||
if let Some(session) = session {
|
if let Some(session) = session {
|
||||||
match session.idle() {
|
match session.idle() {
|
||||||
// BEWARE: If you change the Secure branch you
|
// BEWARE: If you change the Secure branch you
|
||||||
@@ -67,8 +73,8 @@ impl Imap {
|
|||||||
if let Err(err) = handle.init().await {
|
if let Err(err) = handle.init().await {
|
||||||
return Err(Error::IdleProtocolFailed(err));
|
return Err(Error::IdleProtocolFailed(err));
|
||||||
}
|
}
|
||||||
|
let real_timeout = min(timeout, max_duration);
|
||||||
let (idle_wait, interrupt) = handle.wait_with_timeout(timeout);
|
let (idle_wait, interrupt) = handle.wait_with_timeout(real_timeout);
|
||||||
*self.interrupt.lock().await = Some(interrupt);
|
*self.interrupt.lock().await = Some(interrupt);
|
||||||
|
|
||||||
if self.skip_next_idle_wait.load(Ordering::SeqCst) {
|
if self.skip_next_idle_wait.load(Ordering::SeqCst) {
|
||||||
@@ -178,7 +184,12 @@ 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>,
|
||||||
|
timeout: Duration,
|
||||||
|
) {
|
||||||
// Idle using polling. This is also needed if we're not yet configured -
|
// 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).
|
// in this case, we're waiting for a configure job (and an interrupt).
|
||||||
task::block_on(async move {
|
task::block_on(async move {
|
||||||
@@ -213,6 +224,15 @@ impl Imap {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
info!(context, "fake_idle is connected");
|
info!(context, "fake_idle is connected");
|
||||||
|
|
||||||
|
if SystemTime::now()
|
||||||
|
.duration_since(fake_idle_start_time)
|
||||||
|
.unwrap_or_default()
|
||||||
|
> timeout
|
||||||
|
{
|
||||||
|
info!(context, "fake_idle stopping as jobs need running");
|
||||||
|
break;
|
||||||
|
}
|
||||||
// we are connected, let's see if fetching messages results
|
// we are connected, let's see if fetching messages results
|
||||||
// in anything. If so, we behave as if IDLE had data but
|
// in anything. If so, we behave as if IDLE had data but
|
||||||
// will have already fetched the messages so perform_*_fetch
|
// will have already fetched the messages so perform_*_fetch
|
||||||
|
|||||||
@@ -1202,7 +1202,7 @@ fn precheck_imf(context: &Context, rfc724_mid: &str, server_folder: &str, server
|
|||||||
{
|
{
|
||||||
if old_server_folder.is_empty() && old_server_uid == 0 {
|
if old_server_folder.is_empty() && old_server_uid == 0 {
|
||||||
info!(context, "[move] detected bbc-self {}", rfc724_mid,);
|
info!(context, "[move] detected bbc-self {}", rfc724_mid,);
|
||||||
do_heuristics_moves(context, server_folder.as_ref(), msg_id);
|
do_heuristics_moves(context, server_folder, msg_id);
|
||||||
add_job_no_interrupt(
|
add_job_no_interrupt(
|
||||||
context,
|
context,
|
||||||
Action::MarkseenMsgOnImap,
|
Action::MarkseenMsgOnImap,
|
||||||
|
|||||||
@@ -134,13 +134,18 @@ impl JobThread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn idle(&self, context: &Context, use_network: bool) {
|
pub fn idle(&self, context: &Context, use_network: bool) {
|
||||||
|
// standard idle wait timeout
|
||||||
|
let mut timeout = Duration::from_secs(23 * 60);
|
||||||
|
|
||||||
{
|
{
|
||||||
let &(ref lock, ref cvar) = &*self.state.clone();
|
let &(ref lock, ref cvar) = &*self.state.clone();
|
||||||
let mut state = lock.lock().unwrap();
|
let mut state = lock.lock().unwrap();
|
||||||
|
|
||||||
if self.folder_config_name == "INBOX" {
|
// if we are in the inbox (job) thread
|
||||||
let duration = get_next_wakeup_time(context, Thread::Imap);
|
// we check if a job is due.
|
||||||
if duration <= Duration::from_millis(1) {
|
if self.folder_config_name == "configured_inbox_folder" {
|
||||||
|
timeout = get_next_wakeup_time(context, Thread::Imap);
|
||||||
|
if timeout <= Duration::from_millis(20) {
|
||||||
info!(
|
info!(
|
||||||
context,
|
context,
|
||||||
"INBOX-IDLE will not be started because of waiting jobs."
|
"INBOX-IDLE will not be started because of waiting jobs."
|
||||||
@@ -178,7 +183,7 @@ impl JobThread {
|
|||||||
} else {
|
} else {
|
||||||
let watch_folder = self.get_watch_folder(context);
|
let watch_folder = self.get_watch_folder(context);
|
||||||
info!(context, "{} started...", prefix);
|
info!(context, "{} started...", prefix);
|
||||||
let res = self.imap.idle(context, watch_folder);
|
let res = self.imap.idle(context, watch_folder, timeout);
|
||||||
info!(context, "{} ended...", prefix);
|
info!(context, "{} ended...", prefix);
|
||||||
if let Err(err) = res {
|
if let Err(err) = res {
|
||||||
warn!(context, "{} failed: {} -> reconnecting", prefix, err);
|
warn!(context, "{} failed: {} -> reconnecting", prefix, err);
|
||||||
@@ -198,7 +203,7 @@ impl JobThread {
|
|||||||
};
|
};
|
||||||
if do_fake_idle {
|
if do_fake_idle {
|
||||||
let watch_folder = self.get_watch_folder(context);
|
let watch_folder = self.get_watch_folder(context);
|
||||||
self.imap.fake_idle(context, watch_folder);
|
self.imap.fake_idle(context, watch_folder, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.state.0.lock().unwrap().using_handle = false;
|
self.state.0.lock().unwrap().using_handle = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user