Add simple synchronous job API
Signed-off-by: trivernis <trivernis@protonmail.com>pull/4/head
parent
f74bac100b
commit
f374488762
@ -0,0 +1,40 @@
|
||||
use crate::client_api::error::ApiResult;
|
||||
use crate::client_api::IPCApi;
|
||||
use crate::types::jobs::{JobType, RunJobRequest};
|
||||
use bromine::context::{Context, PoolGuard, PooledContext};
|
||||
use std::time::Duration;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct JobApi {
|
||||
ctx: PooledContext,
|
||||
}
|
||||
|
||||
impl IPCApi for JobApi {
|
||||
fn namespace() -> &'static str {
|
||||
"jobs"
|
||||
}
|
||||
|
||||
fn ctx(&self) -> PoolGuard<Context> {
|
||||
self.ctx.acquire()
|
||||
}
|
||||
}
|
||||
|
||||
impl JobApi {
|
||||
pub fn new(ctx: PooledContext) -> Self {
|
||||
Self { ctx }
|
||||
}
|
||||
|
||||
/// Runs a job of the given type and returns when it has finished
|
||||
#[tracing::instrument(level = "debug", skip(self))]
|
||||
pub async fn run_job(&self, job_type: JobType) -> ApiResult<()> {
|
||||
self.emit_and_get(
|
||||
"run_job",
|
||||
RunJobRequest {
|
||||
job_type,
|
||||
sync: true,
|
||||
},
|
||||
Some(Duration::from_secs(300)),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
use crate::tauri_plugin::commands::ApiAccess;
|
||||
use crate::tauri_plugin::error::PluginResult;
|
||||
use crate::types::jobs::JobType;
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn run_job(api_state: ApiAccess<'_>, job_type: JobType) -> PluginResult<()> {
|
||||
let api = api_state.api().await?;
|
||||
api.job.run_job(job_type).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct RunJobRequest {
|
||||
pub job_type: JobType,
|
||||
pub sync: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub enum JobType {
|
||||
MigrateContentDescriptors,
|
||||
CalculateSizes,
|
||||
CheckIntegrity,
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
pub mod files;
|
||||
pub mod identifier;
|
||||
pub mod jobs;
|
||||
pub mod misc;
|
||||
pub mod repo;
|
||||
pub mod tags;
|
||||
|
Loading…
Reference in New Issue