Skip to main content

paperless_api/
task.rs

1//! Types related to tasks.
2
3use derive_more::Display;
4use serde::{Deserialize, Serialize};
5
6/// A paperless task.
7#[derive(Debug, Clone, Deserialize)]
8pub struct Task {
9    /// Unique identifier of the task.
10    pub id: u32,
11
12    /// The Celery-ID of the task.
13    pub task_id: crate::id::TaskId,
14
15    /// The name/kind of the task.
16    #[serde(rename = "task_name")]
17    pub name: TaskName,
18
19    /// The type of the task.
20    #[serde(rename = "type")]
21    pub task_type: TaskType,
22
23    /// The status of the task.
24    pub status: TaskStatus,
25
26    /// The user who owns the task.
27    pub owner: crate::id::UserId,
28
29    /// Whether the task has been acknowledged.
30    pub acknowledged: bool,
31
32    /// The result of the task, if any.
33    pub result: Option<String>,
34
35    /// The ID of the related document, if any.
36    pub related_document: Option<String>,
37}
38
39/// The status of a task.
40#[derive(Debug, Display, Clone, Copy, PartialEq, Eq, Hash, Deserialize)]
41#[serde(rename_all = "UPPERCASE")]
42pub enum TaskStatus {
43    Failure,
44    Pending,
45    Received,
46    Retry,
47    Revoked,
48    Started,
49    Success,
50}
51
52/// The name of a task.
53#[derive(Debug, Display, Clone, Copy, PartialEq, Eq, Hash, Deserialize, Serialize)]
54#[serde(rename_all = "snake_case")]
55pub enum TaskName {
56    ConsumeFile,
57    TrainClassifier,
58    CheckSanity,
59    IndexOptimize,
60}
61
62/// The type of a task.
63#[derive(Debug, Display, Clone, Copy, PartialEq, Eq, Hash, Deserialize, Serialize)]
64#[serde(rename_all = "snake_case")]
65pub enum TaskType {
66    AutoTask,
67    ScheduledTask,
68    ManualTask,
69}