mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
Add PerformJobsNeeded enum (DC_JOBS_NEEDED_* in core)
This commit is contained in:
committed by
Floris Bruynooghe
parent
fe7852b64e
commit
95b90a59dc
@@ -489,12 +489,25 @@ pub struct BobStatus {
|
|||||||
pub qr_scan: Option<Lot>,
|
pub qr_scan: Option<Lot>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub enum PerformJobsNeeded {
|
||||||
|
Not,
|
||||||
|
AtOnce,
|
||||||
|
AvoidDos,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for PerformJobsNeeded {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::Not
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
pub struct SmtpState {
|
pub struct SmtpState {
|
||||||
pub idle: bool,
|
pub idle: bool,
|
||||||
pub suspended: bool,
|
pub suspended: bool,
|
||||||
pub doing_jobs: bool,
|
pub doing_jobs: bool,
|
||||||
pub perform_jobs_needed: i32,
|
pub perform_jobs_needed: PerformJobsNeeded,
|
||||||
pub probe_network: bool,
|
pub probe_network: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
10
src/job.rs
10
src/job.rs
@@ -8,7 +8,7 @@ use crate::chat;
|
|||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::configure::*;
|
use crate::configure::*;
|
||||||
use crate::constants::*;
|
use crate::constants::*;
|
||||||
use crate::context::Context;
|
use crate::context::{Context, PerformJobsNeeded};
|
||||||
use crate::dc_tools::*;
|
use crate::dc_tools::*;
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::events::Event;
|
use crate::events::Event;
|
||||||
@@ -480,7 +480,7 @@ pub fn perform_smtp_jobs(context: &Context) {
|
|||||||
|
|
||||||
let probe_smtp_network = state.probe_network;
|
let probe_smtp_network = state.probe_network;
|
||||||
state.probe_network = false;
|
state.probe_network = false;
|
||||||
state.perform_jobs_needed = 0;
|
state.perform_jobs_needed = PerformJobsNeeded::Not;
|
||||||
|
|
||||||
if state.suspended {
|
if state.suspended {
|
||||||
info!(context, "SMTP-jobs suspended.",);
|
info!(context, "SMTP-jobs suspended.",);
|
||||||
@@ -508,7 +508,7 @@ pub fn perform_smtp_idle(context: &Context) {
|
|||||||
let &(ref lock, ref cvar) = &*context.smtp_state.clone();
|
let &(ref lock, ref cvar) = &*context.smtp_state.clone();
|
||||||
let mut state = lock.lock().unwrap();
|
let mut state = lock.lock().unwrap();
|
||||||
|
|
||||||
if state.perform_jobs_needed == 1 {
|
if state.perform_jobs_needed == PerformJobsNeeded::AtOnce {
|
||||||
info!(
|
info!(
|
||||||
context,
|
context,
|
||||||
"SMTP-idle will not be started because of waiting jobs.",
|
"SMTP-idle will not be started because of waiting jobs.",
|
||||||
@@ -876,7 +876,7 @@ fn job_perform(context: &Context, thread: Thread, probe_network: bool) {
|
|||||||
.0
|
.0
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.perform_jobs_needed = 2;
|
.perform_jobs_needed = PerformJobsNeeded::AvoidDos;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if job.action == Action::SendMsgToSmtp {
|
if job.action == Action::SendMsgToSmtp {
|
||||||
@@ -1008,7 +1008,7 @@ pub fn interrupt_smtp_idle(context: &Context) {
|
|||||||
let &(ref lock, ref cvar) = &*context.smtp_state.clone();
|
let &(ref lock, ref cvar) = &*context.smtp_state.clone();
|
||||||
let mut state = lock.lock().unwrap();
|
let mut state = lock.lock().unwrap();
|
||||||
|
|
||||||
state.perform_jobs_needed = 1;
|
state.perform_jobs_needed = PerformJobsNeeded::AtOnce;
|
||||||
state.idle = true;
|
state.idle = true;
|
||||||
cvar.notify_one();
|
cvar.notify_one();
|
||||||
info!(context, "Interrupting SMTP-idle... ended",);
|
info!(context, "Interrupting SMTP-idle... ended",);
|
||||||
|
|||||||
Reference in New Issue
Block a user