Change the order of job processing

This commit is contained in:
Alexander Krotov
2019-11-28 23:56:39 +01:00
parent 6306c82dfe
commit f7e00364bf

View File

@@ -976,17 +976,19 @@ pub fn interrupt_smtp_idle(context: &Context) {
/// jobs, this is tricky and probably wrong currently. Look at the /// jobs, this is tricky and probably wrong currently. Look at the
/// SQL queries for details. /// SQL queries for details.
fn load_jobs(context: &Context, thread: Thread, probe_network: bool) -> Vec<Job> { fn load_jobs(context: &Context, thread: Thread, probe_network: bool) -> Vec<Job> {
let query = if !probe_network { let query = if probe_network {
// processing for first-try and after backoff-timeouts: // Processing after call to dc_maybe_network():
// process jobs in the order they were added. // process all pending jobs in the order of their priority.
"SELECT id, action, foreign_id, param, added_timestamp, desired_timestamp, tries \ // If jobs have the same priority, process the
FROM jobs WHERE thread=? AND desired_timestamp<=? ORDER BY action DESC, added_timestamp;" // one that was added earlier.
"SELECT id, action, foreign_id, param, added_timestamp, desired_timestamp, tries
FROM jobs WHERE thread=? ORDER BY action DESC, added_timestamp;"
} else { } else {
// processing after call to dc_maybe_network(): // Processing for the first try and after backoff-timeouts:
// process _all_ pending jobs that failed before // process jobs that have their backoff expired
// in the order of their backoff-times. // in the order of their backoff times.
"SELECT id, action, foreign_id, param, added_timestamp, desired_timestamp, tries \ "SELECT id, action, foreign_id, param, added_timestamp, desired_timestamp, tries
FROM jobs WHERE thread=? ORDER BY desired_timestamp, action DESC;" FROM jobs WHERE thread=? AND desired_timestamp<=? ORDER BY desired_timestamp;"
}; };
let params_no_probe = params![thread as i64, time()]; let params_no_probe = params![thread as i64, time()];