pub struct Task {
pub definition: TaskDefinition,
pub status: TaskStatus,
pub result: Option<TaskResult>,
pub retry_count: u32,
pub started_at: Option<DateTime<Utc>>,
pub completed_at: Option<DateTime<Utc>>,
pub assigned_worker: Option<String>,
pub execution_log: Vec<String>,
}Fields§
§definition: TaskDefinition§status: TaskStatus§result: Option<TaskResult>§retry_count: u32§started_at: Option<DateTime<Utc>>§completed_at: Option<DateTime<Utc>>§assigned_worker: Option<String>§execution_log: Vec<String>Implementations§
Source§impl Task
impl Task
Sourcepub fn new(definition: TaskDefinition) -> Self
pub fn new(definition: TaskDefinition) -> Self
Examples found in repository?
examples/simple_execution.rs (lines 14-21)
8async fn main() -> Result<(), Box<dyn std::error::Error>> {
9 println!("Testing handler execution directly...\n");
10
11 // Test Python handler
12 println!("=== Testing Python Handler ===");
13 let python_handler = PythonTaskHandler::new();
14 let python_task = Task::new(
15 TaskDefinition::new("test-python", "python_script")
16 .with_payload(
17 "script",
18 json!("print('Hello from direct execution!'); x = 5 + 3; print(f'5 + 3 = {x}')"),
19 )
20 .with_payload("args", json!([])),
21 );
22
23 match python_handler.execute(&python_task).await {
24 Ok(result) => {
25 println!("Python execution successful: {}", result.success);
26 println!("Output: {:?}", result.output);
27 }
28 Err(e) => println!("Python execution failed: {}", e),
29 }
30
31 println!("\n=== Testing File Handler ===");
32 // Test File handler
33 let file_handler = FileTaskHandler::new();
34
35 // Create a test file
36 let create_task = Task::new(
37 TaskDefinition::new("test-create", "file_operation")
38 .with_payload("operation", json!("write"))
39 .with_payload("path", json!("/tmp/test_direct.txt"))
40 .with_payload(
41 "content",
42 json!("This was created by direct handler execution\nTest successful!"),
43 ),
44 );
45
46 match file_handler.execute(&create_task).await {
47 Ok(result) => {
48 println!("File creation successful: {}", result.success);
49 println!("Output: {:?}", result.output);
50 }
51 Err(e) => println!("File creation failed: {}", e),
52 }
53
54 // Read the file back
55 println!("\n=== Testing File Read ===");
56 let read_task = Task::new(
57 TaskDefinition::new("test-read", "file_operation")
58 .with_payload("operation", json!("read"))
59 .with_payload("path", json!("/tmp/test_direct.txt")),
60 );
61
62 match file_handler.execute(&read_task).await {
63 Ok(result) => {
64 println!("File read successful: {}", result.success);
65 if let Some(content) = result.output {
66 println!("File content: {}", content);
67 }
68 }
69 Err(e) => println!("File read failed: {}", e),
70 }
71
72 // Cleanup
73 println!("\n=== Cleaning Up ===");
74 let delete_task = Task::new(
75 TaskDefinition::new("test-delete", "file_operation")
76 .with_payload("operation", json!("delete"))
77 .with_payload("path", json!("/tmp/test_direct.txt")),
78 );
79
80 match file_handler.execute(&delete_task).await {
81 Ok(result) => println!("File cleanup successful: {}", result.success),
82 Err(e) => println!("File cleanup failed: {}", e),
83 }
84
85 println!("\nDirect handler execution test completed!");
86 Ok(())
87}pub fn start_execution(&mut self, worker_id: &str)
pub fn complete_execution(&mut self, result: TaskResult)
pub fn fail_execution(&mut self, error: &str)
pub fn retry(&mut self)
pub fn cancel(&mut self)
pub fn can_retry(&self) -> bool
pub fn is_ready_to_execute(&self) -> bool
pub fn is_finished(&self) -> bool
pub fn add_log(&mut self, message: &str)
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Task
impl<'de> Deserialize<'de> for Task
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Task
impl RefUnwindSafe for Task
impl Send for Task
impl Sync for Task
impl Unpin for Task
impl UnwindSafe for Task
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more