External Task Worker for Operaton in Rust

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 :slight_smile: Contributions are also very welcome!

3 Likes

Hey cool, left you a :star: I’m pretty sure this will be helpful for some users. This crate looks really lighweight.

I think we should build a kind of marketplace some day to make tools und other add-ons visible.

1 Like

Thank you very much! Yes, I think that a ‘marketplace’ would be a great idea and I would be happy to see my little project as a part of it!

@reckeljm We have now added the new page Hub - Operaton
Please use the link on the page to request your project to be listed-

1 Like

Thank you, I’ve added an issue: [Hub]: Add Operaton Task Worker Rust crate to the Hub · Issue #60 · operaton/operaton.org · GitHub

1 Like

Thank you, added the entry now.