From 9ef0b43c36fb3e6c6ba75b6826238f94a0dd23ff Mon Sep 17 00:00:00 2001 From: link2xt Date: Sun, 17 Apr 2022 00:00:00 +0000 Subject: [PATCH] Remove job::{Action,Thread}::Unknown variants --- src/job.rs | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/src/job.rs b/src/job.rs index aacd34322..9e6995639 100644 --- a/src/job.rs +++ b/src/job.rs @@ -4,7 +4,7 @@ //! and job types. use std::fmt; -use anyhow::{bail, format_err, Context as _, Result}; +use anyhow::{format_err, Context as _, Result}; use deltachat_derive::{FromSql, ToSql}; use rand::{thread_rng, Rng}; @@ -31,7 +31,6 @@ const JOB_RETRIES: u32 = 17; )] #[repr(u32)] pub(crate) enum Thread { - Unknown = 0, Imap = 100, Smtp = 5000, } @@ -59,12 +58,6 @@ macro_rules! job_try { }; } -impl Default for Thread { - fn default() -> Self { - Thread::Unknown - } -} - #[derive( Debug, Display, @@ -80,8 +73,6 @@ impl Default for Thread { )] #[repr(u32)] pub enum Action { - Unknown = 0, - // Jobs in the INBOX-thread, range from DC_IMAP_THREAD..DC_IMAP_THREAD+999 FetchExistingMsgs = 110, @@ -104,19 +95,11 @@ pub enum Action { SendMdn = 5010, } -impl Default for Action { - fn default() -> Self { - Action::Unknown - } -} - impl From for Thread { fn from(action: Action) -> Thread { use Action::*; match action { - Unknown => Thread::Unknown, - FetchExistingMsgs => Thread::Imap, ResyncFolders => Thread::Imap, UpdateRecentQuota => Thread::Imap, @@ -587,7 +570,6 @@ async fn perform_job_action( ); let try_res = match job.action { - Action::Unknown => Status::Finished(Err(format_err!("Unknown job id found"))), Action::SendMdn => job.send_mdn(context, connection.smtp()).await, Action::MaybeSendLocations => location::job_maybe_send_locations(context, job).await, Action::MaybeSendLocationsEnded => { @@ -658,7 +640,6 @@ pub async fn add(context: &Context, job: Job) -> Result<()> { if delay_seconds == 0 { match action { - Action::Unknown => unreachable!(), Action::ResyncFolders | Action::FetchExistingMsgs | Action::UpdateRecentQuota @@ -718,7 +699,7 @@ LIMIT 1; params = paramsv![thread_i]; }; - let job = loop { + loop { let job_res = context .sql .query_row_optional(query, params.clone(), |row| { @@ -737,7 +718,7 @@ LIMIT 1; .await; match job_res { - Ok(job) => break job, + Ok(job) => return Ok(job), Err(err) => { // Remove invalid job from the DB info!(context, "cleaning up job, because of {}", err); @@ -755,13 +736,6 @@ LIMIT 1; .with_context(|| format!("Failed to delete invalid job {}", id))?; } } - }; - - match thread { - Thread::Unknown => { - bail!("unknown thread for job") - } - Thread::Imap | Thread::Smtp => Ok(job), } }