Hello everyone,
As I am going to test the usage of applying Operaton to my scientific instution, I implemented the light Rust crate Operaton Task Worker for handling external tasks (Service Tasks). With that, implementing external task handlers just needs a few lines of code:
use operaton_task_worker::{poll, settings};
use operaton_task_worker_macros::task_handler;
/// The prefix for all environment variables used by Operaton Task Worker
///
/// Note: This does not apply for Rust-specific environment variables such as `LOGLEVEL`.
pub const ENV_PREFIX: &str = "OPERATON_TASK_WORKER";
#[tokio::main]
async fn main() {
// Get the parameters from the environment variables
let config = settings::load_config_from_env(ENV_PREFIX);
// Or set them manually via the builder pattern
let config = ConfigParams::default()
.with_url(Url::parse("http://localhost:8080").unwrap())
.with_auth("user".to_string(), "pass".to_string())
.with_poll_interval(1000)
.with_worker_id("operaton_task_worker".to_string());
// Start the polling
poll(config).await;
}
// This is how task handlers get implemented
#[task_handler(name = "ServiceTask_Grant_Approval")]
fn service_task_grant_approval(_input: &operaton_task_worker::types::InputVariables) -> Result<operaton_task_worker::types::OutputVariables, Box<dyn std::error::Error>> {
// Do something
Ok(std::collections::HashMap::new()) // Put variables here or return errors (see documentation)
}
That’s basically everything you’ll need to do, the API abstractions are taken care of by the Crate.
I release this crate under the MIT license, so feel free to use it also for your commercial projects.
If you like the project, I would be happy if you also check out the Github Repository and consider giving a star
Contributions are also very welcome!