feat: with module example and api
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
ac246c2d18
commit
9676c6aefb
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -929,6 +929,10 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "example-module"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "eyre"
|
||||
version = "0.6.8"
|
||||
|
16
examples/example-module/Cargo.toml
Normal file
16
examples/example-module/Cargo.toml
Normal 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]
|
||||
|
||||
|
85
examples/example-module/src/lib.rs
Normal file
85
examples/example-module/src/lib.rs
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user