mark failed jobs with a specific state, prevent from lingering in ui

feat/vaults
Tomáš Mládek 2021-06-20 16:46:45 +02:00
parent ba19b5694b
commit 942ccf1c40
4 changed files with 24 additions and 4 deletions

View File

@ -6,7 +6,7 @@ use crate::database::{
TYPE_INSTANCED_ATTR, TYPE_IS_ATTR, TYPE_REQUIRES_ATTR, TYPE_INSTANCED_ATTR, TYPE_IS_ATTR, TYPE_REQUIRES_ATTR,
}; };
use crate::hash::Hashable; use crate::hash::Hashable;
use crate::jobs::{Job, JobContainer, JobId}; use crate::jobs::{Job, JobContainer, JobId, State};
use crate::models; use crate::models;
use crate::models::File; use crate::models::File;
use anyhow::{anyhow, Error, Result}; use anyhow::{anyhow, Error, Result};
@ -363,11 +363,20 @@ pub async fn rescan_vault(
.add_job(Job::new("REIMPORT", "Reimporting vault...")) .add_job(Job::new("REIMPORT", "Reimporting vault..."))
.unwrap(); .unwrap();
let job_container_rescan = job_container.clone();
let result = let result =
actix_web::web::block(move || _rescan_vault(pool, directory, job_container, job_id)).await; actix_web::web::block(move || _rescan_vault(pool, directory, job_container_rescan, job_id))
.await;
if result.is_err() { if result.is_err() {
let err = result.err().unwrap(); let err = result.err().unwrap();
error!("Update did not succeed! {:?}", err); error!("Update did not succeed! {:?}", err);
job_container
.write()
.unwrap()
.update_state(&job_id, State::Failed)
.unwrap();
} }
} }

View File

@ -27,6 +27,7 @@ pub type JobType = String;
pub enum State { pub enum State {
InProgress, InProgress,
Done, Done,
Failed,
} }
impl Default for State { impl Default for State {
@ -40,7 +41,7 @@ pub struct JobContainer {
jobs: HashMap<JobId, Job>, jobs: HashMap<JobId, Job>,
} }
#[derive(Clone, Hash, PartialEq, Eq)] #[derive(Clone, Hash, PartialEq, Eq, Copy)]
pub struct JobId { pub struct JobId {
uuid: Uuid, uuid: Uuid,
} }
@ -82,4 +83,13 @@ impl JobContainer {
Err(anyhow!("No such job.")) Err(anyhow!("No such job."))
} }
} }
pub fn update_state(&mut self, id: &JobId, state: State) -> Result<()> {
if let Some(job) = self.jobs.get_mut(id) {
job.state = state;
Ok(())
} else {
Err(anyhow!("No such job."))
}
}
} }

View File

@ -27,7 +27,7 @@ export default defineComponent({
computed: { computed: {
activeJobs(): JobWithId[] { activeJobs(): JobWithId[] {
return Object.entries(this.jobs) return Object.entries(this.jobs)
.filter(([_, job]) => job.progress < 100) .filter(([_, job]) => job.state == "InProgress")
.map(([id, job]) => { .map(([id, job]) => {
return { id, ...job }; return { id, ...job };
}); });

View File

@ -14,6 +14,7 @@ export interface ListingResult {
export interface Job { export interface Job {
title: string; title: string;
progress: number; progress: number;
state: "InProgress" | "Done" | "Failed",
} }
export interface IFile { export interface IFile {