mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
avoid inbox jobs_needed flag
This commit is contained in:
@@ -44,7 +44,6 @@ pub struct Context {
|
|||||||
/// Blob directory path
|
/// Blob directory path
|
||||||
blobdir: PathBuf,
|
blobdir: PathBuf,
|
||||||
pub sql: Sql,
|
pub sql: Sql,
|
||||||
pub perform_inbox_jobs_needed: Arc<RwLock<bool>>,
|
|
||||||
pub probe_imap_network: Arc<RwLock<bool>>,
|
pub probe_imap_network: Arc<RwLock<bool>>,
|
||||||
pub inbox_thread: Arc<RwLock<JobThread>>,
|
pub inbox_thread: Arc<RwLock<JobThread>>,
|
||||||
pub sentbox_thread: Arc<RwLock<JobThread>>,
|
pub sentbox_thread: Arc<RwLock<JobThread>>,
|
||||||
@@ -147,7 +146,6 @@ impl Context {
|
|||||||
Imap::new(),
|
Imap::new(),
|
||||||
))),
|
))),
|
||||||
probe_imap_network: Arc::new(RwLock::new(false)),
|
probe_imap_network: Arc::new(RwLock::new(false)),
|
||||||
perform_inbox_jobs_needed: Arc::new(RwLock::new(false)),
|
|
||||||
generating_key_mutex: Mutex::new(()),
|
generating_key_mutex: Mutex::new(()),
|
||||||
translated_stockstrings: RwLock::new(HashMap::new()),
|
translated_stockstrings: RwLock::new(HashMap::new()),
|
||||||
};
|
};
|
||||||
|
|||||||
16
src/job.rs
16
src/job.rs
@@ -35,7 +35,7 @@ const JOB_RETRIES: u32 = 17;
|
|||||||
/// Thread IDs
|
/// Thread IDs
|
||||||
#[derive(Debug, Display, Copy, Clone, PartialEq, Eq, FromPrimitive, ToPrimitive, FromSql, ToSql)]
|
#[derive(Debug, Display, Copy, Clone, PartialEq, Eq, FromPrimitive, ToPrimitive, FromSql, ToSql)]
|
||||||
#[repr(i32)]
|
#[repr(i32)]
|
||||||
enum Thread {
|
pub enum Thread {
|
||||||
Unknown = 0,
|
Unknown = 0,
|
||||||
Imap = 100,
|
Imap = 100,
|
||||||
Smtp = 5000,
|
Smtp = 5000,
|
||||||
@@ -436,13 +436,6 @@ pub fn perform_sentbox_fetch(context: &Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn perform_inbox_idle(context: &Context) {
|
pub fn perform_inbox_idle(context: &Context) {
|
||||||
if *context.perform_inbox_jobs_needed.clone().read().unwrap() {
|
|
||||||
info!(
|
|
||||||
context,
|
|
||||||
"INBOX-IDLE will not be started because of waiting jobs."
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let use_network = context.get_config_bool(Config::InboxWatch);
|
let use_network = context.get_config_bool(Config::InboxWatch);
|
||||||
|
|
||||||
context
|
context
|
||||||
@@ -552,7 +545,7 @@ pub fn perform_smtp_idle(context: &Context) {
|
|||||||
info!(context, "SMTP-idle ended.",);
|
info!(context, "SMTP-idle ended.",);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_next_wakeup_time(context: &Context, thread: Thread) -> Duration {
|
pub(crate) fn get_next_wakeup_time(context: &Context, thread: Thread) -> Duration {
|
||||||
let t: i64 = context
|
let t: i64 = context
|
||||||
.sql
|
.sql
|
||||||
.query_get_value(
|
.query_get_value(
|
||||||
@@ -704,7 +697,6 @@ pub fn perform_inbox_jobs(context: &Context) {
|
|||||||
|
|
||||||
let probe_imap_network = *context.probe_imap_network.clone().read().unwrap();
|
let probe_imap_network = *context.probe_imap_network.clone().read().unwrap();
|
||||||
*context.probe_imap_network.write().unwrap() = false;
|
*context.probe_imap_network.write().unwrap() = false;
|
||||||
*context.perform_inbox_jobs_needed.write().unwrap() = false;
|
|
||||||
|
|
||||||
job_perform(context, Thread::Imap, probe_imap_network);
|
job_perform(context, Thread::Imap, probe_imap_network);
|
||||||
info!(context, "dc_perform_inbox_jobs ended.",);
|
info!(context, "dc_perform_inbox_jobs ended.",);
|
||||||
@@ -951,10 +943,6 @@ pub fn add_job_no_interrupt(
|
|||||||
(timestamp + delay_seconds as i64)
|
(timestamp + delay_seconds as i64)
|
||||||
]
|
]
|
||||||
).ok();
|
).ok();
|
||||||
|
|
||||||
if thread == Thread::Imap {
|
|
||||||
*context.perform_inbox_jobs_needed.write().unwrap() = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_job_with_interrupt(
|
pub fn add_job_with_interrupt(
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ use std::sync::{Arc, Condvar, Mutex};
|
|||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::error::{Error, Result};
|
use crate::error::{Error, Result};
|
||||||
use crate::imap::Imap;
|
use crate::imap::Imap;
|
||||||
|
use crate::job::{get_next_wakeup_time, Thread};
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct JobThread {
|
pub struct JobThread {
|
||||||
@@ -57,10 +59,6 @@ impl JobThread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn interrupt_idle(&self, context: &Context) {
|
pub fn interrupt_idle(&self, context: &Context) {
|
||||||
{
|
|
||||||
self.state.0.lock().unwrap().jobs_needed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
info!(context, "Interrupting {}-IDLE...", self.name);
|
info!(context, "Interrupting {}-IDLE...", self.name);
|
||||||
|
|
||||||
self.imap.interrupt_idle(context);
|
self.imap.interrupt_idle(context);
|
||||||
@@ -140,15 +138,16 @@ impl JobThread {
|
|||||||
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 state.jobs_needed {
|
if self.folder_config_name == "INBOX" {
|
||||||
|
let duration = get_next_wakeup_time(context, Thread::Imap);
|
||||||
|
if duration <= Duration::from_millis(1) {
|
||||||
info!(
|
info!(
|
||||||
context,
|
context,
|
||||||
"{}-IDLE will not be started as it was interrupted while not ideling.",
|
"INBOX-IDLE will not be started because of waiting jobs."
|
||||||
self.name,
|
|
||||||
);
|
);
|
||||||
state.jobs_needed = false;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if state.suspended {
|
if state.suspended {
|
||||||
while !state.idle {
|
while !state.idle {
|
||||||
|
|||||||
Reference in New Issue
Block a user