;
This commit is contained in:
1 parent
9268833a3c
commit
314b7445a1
27 files changed
+1830
No files matched your search
@@ -0,0 +1,16 @@
|
||||
[package]
|
||||
name = "chronos-core"
|
||||
version = { workspace = true }
|
||||
edition = "2021"
|
||||
authors = ["Chronos Team"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
homepage = "https://github.com/chronos/chronos"
|
||||
repository = "https://github.com/chronos/chronos"
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
tokio = { version = "1.0", features = ["full"] }
|
||||
sqlx = { version = "0.7", features = ["postgres", "runtime-tokio-rustls"] }
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
thiserror = "1.0"
|
||||
anyhow = "1.0"
|
||||
@@ -0,0 +1,111 @@
|
||||
//! Core data models and shared types for Chronos
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use chrono::{DateTime, Utc};
|
||||
use uuid::Uuid;
|
||||
|
||||
/// User role enumeration
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, sqlx::Type)]
|
||||
#[sqlx(type_name = "role", rename_all = "lowercase")]
|
||||
pub enum Role {
|
||||
Administrator,
|
||||
Operator,
|
||||
Viewer,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Role {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Role::Administrator => write!(f, "administrator"),
|
||||
Role::Operator => write!(f, "operator"),
|
||||
Role::Viewer => write!(f, "viewer"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// User entity
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct User {
|
||||
pub id: Uuid,
|
||||
pub username: String,
|
||||
pub password_hash: String,
|
||||
pub role: Role,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
/// Session entity
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Session {
|
||||
pub id: Uuid,
|
||||
pub user_id: Uuid,
|
||||
pub token: String,
|
||||
pub expires_at: DateTime<Utc>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
/// Workflow node type enumeration
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, sqlx::Type)]
|
||||
#[sqlx(type_name = "node_type", rename_all = "lowercase")]
|
||||
pub enum NodeType {
|
||||
Command,
|
||||
Script,
|
||||
Http,
|
||||
Delay,
|
||||
Conditional,
|
||||
DataTransform,
|
||||
FileOperation,
|
||||
Notification,
|
||||
WebhookTrigger,
|
||||
ScheduleTrigger,
|
||||
}
|
||||
|
||||
/// Workflow entity
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Workflow {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
/// Schedule entity
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Schedule {
|
||||
pub id: Uuid,
|
||||
pub workflow_id: Uuid,
|
||||
pub name: String,
|
||||
pub cron_expression: Option<String>,
|
||||
pub interval_seconds: Option<u64>,
|
||||
pub start_date: Option<DateTime<Utc>>,
|
||||
pub end_date: Option<DateTime<Utc>>,
|
||||
pub enabled: bool,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
/// Execution status enumeration
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, sqlx::Type)]
|
||||
#[sqlx(type_name = "execution_status", rename_all = "lowercase")]
|
||||
pub enum ExecutionStatus {
|
||||
Pending,
|
||||
Running,
|
||||
Completed,
|
||||
Failed,
|
||||
Cancelled,
|
||||
Skipped,
|
||||
}
|
||||
|
||||
/// Execution entity
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Execution {
|
||||
pub id: Uuid,
|
||||
pub workflow_id: Uuid,
|
||||
pub schedule_id: Option<Uuid>,
|
||||
pub status: ExecutionStatus,
|
||||
pub started_at: DateTime<Utc>,
|
||||
pub finished_at: Option<DateTime<Utc>>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
Reference in new issue
Block a user