PythonTaskHandler

Struct PythonTaskHandler 

Source
pub struct PythonTaskHandler;

Implementations§

Source§

impl PythonTaskHandler

Source

pub fn new() -> Self

Examples found in repository?
examples/simple_execution.rs (line 13)
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}

Trait Implementations§

Source§

impl TaskHandler for PythonTaskHandler

Source§

fn task_type(&self) -> &'static str

Source§

fn execute<'life0, 'life1, 'async_trait>( &'life0 self, task: &'life1 Task, ) -> Pin<Box<dyn Future<Output = Result<TaskResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Chain<T> for T

Source§

fn len(&self) -> usize

The number of items that this chain link consists of.
Source§

fn append_to(self, v: &mut Vec<T>)

Append the elements in this link to the chain.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,