use log::{error, info}; use serde_json::Value; use tokio::time::sleep; use elf_rust::*; #[tokio::main] async fn main() { env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("debug")) .format(json_format) .init(); let mut app = App::new(); app.add_script(MyScript::new("test", test)); app.add_script(MyScript::new("my_test", test1)); let mut executor = Executor::new(); executor.set_task(app.into()); executor.set_after_action(|_ctx, payload, result| { let runtime = _ctx.get(KEY_RUNTIME).unwrap(); info!("task executed with payload: {}, result: {:?}, runtime {}", payload.to_string(), result.clone().unwrap(),runtime); result }); // cargo run -- --payload '{"tasks":["t","tf"]}' executor.run().await.expect("executor failed to run"); } async fn test(ctx: Context, input: Value) -> Result { info!("test {} runtime {}", input,ctx.get(KEY_RUNTIME).unwrap().to_string()); sleep(std::time::Duration::from_secs(2)).await; Ok("test".into()) } async fn test1(_ctx: Context, input: Value) -> Result { error!("test_1 {}", input); Err("test".into()) }