From 9676c6aefb556d83e5f256124e959ff7e8090d7d Mon Sep 17 00:00:00 2001 From: kjuulh Date: Thu, 31 Aug 2023 22:18:38 +0200 Subject: [PATCH] feat: with module example and api Signed-off-by: kjuulh --- Cargo.lock | 4 ++ examples/example-module/Cargo.toml | 16 ++++++ examples/example-module/src/lib.rs | 85 ++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 examples/example-module/Cargo.toml create mode 100644 examples/example-module/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index aa4ca6e..d8a2f0f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -929,6 +929,10 @@ dependencies = [ "libc", ] +[[package]] +name = "example-module" +version = "0.1.0" + [[package]] name = "eyre" version = "0.6.8" diff --git a/examples/example-module/Cargo.toml b/examples/example-module/Cargo.toml new file mode 100644 index 0000000..13349b1 --- /dev/null +++ b/examples/example-module/Cargo.toml @@ -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] + + diff --git a/examples/example-module/src/lib.rs b/examples/example-module/src/lib.rs new file mode 100644 index 0000000..f220e15 --- /dev/null +++ b/examples/example-module/src/lib.rs @@ -0,0 +1,85 @@ +use std::any::Any; + +pub struct Orchestrator {} + +impl Orchestrator { + pub fn cron(&self, cron: impl AsRef) -> Scheduler { + Scheduler {} + } + + pub fn query(&self, query: Query) -> Response { + Response::Tags { list: Vec::new() } + } + + pub fn api(&self, request: A) -> Response { + Response::Tags { list: Vec::new() } + } +} + +pub enum Query { + Tags(String), +} + +pub enum Response { + Tags { list: Vec }, +} + +#[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(&self, action: A) -> Scheduler { + return self.clone(); + } + + pub async fn apply(&self) {} +} + +pub struct DebianPkg {} + +impl DebianPkg { + pub fn require<'a>(pkgs: impl Into>) -> 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; +}