use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use uuid::Uuid;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TaskDefinition {
pub id: String,
pub name: String,
pub task_type: String,
pub payload: HashMap<String, serde_json::Value>,
pub priority: i32,
pub max_retries: u32,
pub timeout_seconds: u64,
pub dependencies: Vec<String>,
pub tags: Vec<String>,
pub created_at: DateTime<Utc>,
pub scheduled_at: Option<DateTime<Utc>>,
}
impl TaskDefinition {
pub fn new(name: &str, task_type: &str) -> Self {
Self {
id: Uuid::new_v4().to_string(),
name: name.to_string(),
task_type: task_type.to_string(),
payload: HashMap::new(),
priority: 0,
max_retries: 3,
timeout_seconds: 300,
dependencies: Vec::new(),
tags: Vec::new(),
created_at: Utc::now(),
scheduled_at: None,
}
}
pub fn with_payload(mut self, key: &str, value: serde_json::Value) -> Self {
self.payload.insert(key.to_string(), value);
self
}
pub fn with_priority(mut self, priority: i32) -> Self {
self.priority = priority;
self
}
pub fn with_timeout(mut self, timeout_seconds: u64) -> Self {
self.timeout_seconds = timeout_seconds;
self
}
pub fn with_dependencies(mut self, dependencies: Vec<String>) -> Self {
self.dependencies = dependencies;
self
}
pub fn with_tags(mut self, tags: Vec<String>) -> Self {
self.tags = tags;
self
}
pub fn schedule_at(mut self, scheduled_at: DateTime<Utc>) -> Self {
self.scheduled_at = Some(scheduled_at);
self
}
}