feat: with module example and api

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2023-08-31 22:18:38 +02:00
parent ac246c2d18
commit 9676c6aefb
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394
3 changed files with 105 additions and 0 deletions

4
Cargo.lock generated
View File

@ -929,6 +929,10 @@ dependencies = [
"libc",
]
[[package]]
name = "example-module"
version = "0.1.0"
[[package]]
name = "eyre"
version = "0.6.8"

View File

@ -0,0 +1,16 @@
[package]
name = "example-module"
repository.workspace = true
description.workspace = true
readme.workspace = true
license-file.workspace = true
authors.workspace = true
version.workspace = true
edition.workspace = true
[lib]
crate-type = ["cdylib"]
[dependencies]

View File

@ -0,0 +1,85 @@
use std::any::Any;
pub struct Orchestrator {}
impl Orchestrator {
pub fn cron(&self, cron: impl AsRef<str>) -> Scheduler {
Scheduler {}
}
pub fn query(&self, query: Query) -> Response {
Response::Tags { list: Vec::new() }
}
pub fn api<A: Any>(&self, request: A) -> Response {
Response::Tags { list: Vec::new() }
}
}
pub enum Query {
Tags(String),
}
pub enum Response {
Tags { list: Vec<String> },
}
#[derive(Clone)]
pub struct Scheduler {}
pub trait Ensure {
type EnsureInput;
type EnsureOutput;
fn ensure(&self, input: Self::EnsureInput) -> Self::EnsureOutput;
}
pub trait Action {
type Input;
type Output;
fn call(&self, input: Self::Input) -> Self::Output;
}
impl Scheduler {
pub fn schedule<A: Action>(&self, action: A) -> Scheduler {
return self.clone();
}
pub async fn apply(&self) {}
}
pub struct DebianPkg {}
impl DebianPkg {
pub fn require<'a>(pkgs: impl Into<Vec<&'a str>>) -> Self {
Self {}
}
}
impl Ensure for DebianPkg {
type EnsureInput = ();
type EnsureOutput = ();
fn ensure(&self, input: Self::EnsureInput) -> Self::EnsureOutput {}
}
impl Action for DebianPkg {
type Input = ();
type Output = ();
fn call(&self, input: Self::Input) -> Self::Output {}
}
pub async fn handle(orchestrator: Orchestrator) {
orchestrator
.cron("* * * * *")
.schedule(DebianPkg::require(vec!["openssl", "git"]))
.apply()
.await;
orchestrator
.cron("* * * * *")
.schedule(DebianPkg::require(vec!["openssl", "git"]))
.apply()
.await;
}