1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

#[derive(PartialEq, Eq, Serialize, Deserialize, Clone, Debug, Default)]
pub struct EntityConnector {
    /// field key of the schema
    pub field: String,

    /// Unique identifier of a schema
    pub value: String,

    /// Version of a schema
    pub version: Option<String>,

    /// Name of the the schema
    pub entity: String,
}

/// # JobStatus
///
/// Enum for current schema status. Defaults to idle
#[derive(
    PartialEq,
    Eq,
    Serialize,
    Deserialize,
    Clone,
    Debug,
    strum_macros::AsRefStr,
    strum_macros::EnumString,
    strum_macros::IntoStaticStr,
)]
pub enum JobProcessStatus {
    Running,
    Pending,
    Queued,
    Completed,
    Cancelled,
    Failed,
    Skipped,
}

/// Implements default value for a `JobStatus` which is `Queued`
impl Default for JobProcessStatus {
    fn default() -> Self {
        JobProcessStatus::Queued
    }
}

#[derive(PartialEq, Eq, Serialize, Deserialize, Clone, Debug, Default)]
pub struct JobMetadata {
    /// Date the entity was created
    pub last_run: Option<chrono::DateTime<chrono::Utc>>,
}

#[derive(PartialEq, Eq, Serialize, Deserialize, Clone, Debug, Default)]
pub struct OwnerMetadata {
    /// Date the entity was created
    pub created_by: Option<String>,
}

/// Wakflo value which is just an alias for serde_json::Value
pub type Value = serde_json::Value;

#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Default)]
pub struct RunOutput {
    pub output: HashMap<String, serde_json::Value>,
    pub errors: Vec<SystemActivityLog>,
}

pub type TaskResult = anyhow::Result<RunOutput>;

pub type PluginResult = anyhow::Result<serde_json::Value>;

pub fn plugin_json_response<T>(output: RunOutput) -> PluginResult
where
    T: serde::de::DeserializeOwned + serde::Serialize,
{
    let res = serde_json::to_value(output).expect("");
    Ok(res)
}

pub fn task_json_response(output: RunOutput) -> TaskResult {
    Ok(output)
}

#[derive(Serialize, PartialEq, Eq, Deserialize, Clone, Debug, Default)]
pub struct SystemActivityLog {
    pub scope: String,
    pub message: String,
    pub level: String,
    pub timestamp: i64,
}