cosmicus 0.1.9

Cosmicus Client and Server to make the runner better
Documentation
use cosmicus::{
  runner::{Runner, WorkflowMessage, WorkflowRunner},
  Client, ClientPlugin,
};

struct MyPlugin;

impl ClientPlugin for MyPlugin {
  fn on_init(&self, _runner: &Runner) {
    log::info!("MyPlugin init");
  }

  fn on_event(&self, event: &WorkflowMessage) {
    log::info!("MyPlugin on_event: {:?}", event);
  }

  fn on_workflow_runner_init(&self, _runner: &WorkflowRunner) {
    log::info!("MyPlugin on_workflow_runner_init");
  }
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
  let _res = env_logger::builder()
    .target(env_logger::Target::Stdout)
    .filter_level(log::LevelFilter::Info)
    .try_init();

  let client = Client::builder()
    .id("runner")
    .url("ws://localhost:5001")
    .build()?;

  client.register_plugin(MyPlugin {});

  let mut connect_times = 0;
  loop {
    log::info!("Connecting... {}", connect_times);
    if let Err(err) = client.connect().await {
      log::error!("Error connecting: {}", err);
      tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
    }
    connect_times += 1;
  }
}