diff --git a/Cargo.toml b/Cargo.toml index 63091ce2..72622787 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ readme = "README.md" license = "Hippocratic-2.1" [features] -distributed = ["chrono", "cached", "async-std", "turbolift_macros/distributed"] +distributed = ["chrono", "async-std", "turbolift_macros/distributed"] service = ["serde_json"] # todo we can optimize reqs for children with this load @@ -17,6 +17,6 @@ turbolift_macros = { path = "./turbolift_macros" } turbolift_internals = { path = "./turbolift_internals" } async-std = { version = "1.6", optional = true } chrono = { version = "0.4", optional = true } -cached = { version = "0.19", optional = true } +cached = { version = "0.19" } actix-web = { version = "3" } serde_json = { version = "1", optional = true } \ No newline at end of file diff --git a/examples/kubernetes_example/Cargo.toml b/examples/kubernetes_example/Cargo.toml index 5ee7c45a..d6e1afbb 100644 --- a/examples/kubernetes_example/Cargo.toml +++ b/examples/kubernetes_example/Cargo.toml @@ -8,4 +8,9 @@ edition = "2018" "distributed" = ["turbolift/distributed"] [dependencies] +rand = "0.7" +async-std = "1" +lazy_static = "1" +futures = "0.3" +cute = "0.3" turbolift = { path="../../" } \ No newline at end of file diff --git a/examples/kubernetes_example/example_runtime.sh b/examples/kubernetes_example/example_runtime.sh index cb89e8b6..423f63dc 100644 --- a/examples/kubernetes_example/example_runtime.sh +++ b/examples/kubernetes_example/example_runtime.sh @@ -12,4 +12,6 @@ RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo +nightly test --features "distr # run RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo +nightly run -RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo +nightly run --features "distributed" \ No newline at end of file +RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo +nightly run --features "distributed" + +../../kind delete cluster \ No newline at end of file diff --git a/examples/kubernetes_example/src/main.rs b/examples/kubernetes_example/src/main.rs index e7a11a96..9b7f9c74 100644 --- a/examples/kubernetes_example/src/main.rs +++ b/examples/kubernetes_example/src/main.rs @@ -1,3 +1,47 @@ +use std::sync::Mutex; + +#[macro_use] +extern crate lazy_static; +#[macro_use(c)] +extern crate cute; +use futures::future::try_join_all; +use rand::{thread_rng, Rng}; +use turbolift::kubernetes::K8s; +use turbolift::on; + +lazy_static! { + static ref K8S: Mutex = Mutex::new(K8s::new()); +} + +#[on(K8S)] +fn square(u: u64) -> u64 { + u * u +} + +fn random_numbers() -> Vec { + let mut pseud = thread_rng(); + c![pseud.gen_range(0, 1000), for _i in 1..10] +} + fn main() { - println!("Hello, world!"); + let input = random_numbers(); + let futures = c![square(*int), for int in &input]; + let output = async_std::task::block_on(try_join_all(futures)).unwrap(); + println!("input: {:?}\noutput: {:?}", input, output); +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let input = random_numbers(); + let futures = c![square(*int), for int in &input]; + let output = async_std::task::block_on(try_join_all(futures)).unwrap(); + assert_eq!( + output, + input.into_iter().map(|x| x * x).collect::>() + ); + } } diff --git a/src/lib.rs b/src/lib.rs index 1253f800..98d1c39c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,14 +1,14 @@ #[cfg(feature = "distributed")] pub use async_std; #[cfg(feature = "distributed")] -pub use cached; -#[cfg(feature = "distributed")] pub use chrono; -pub use actix_web; #[cfg(feature = "service")] pub use serde_json; +pub use actix_web; +pub use cached; + pub use distributed_platform::{DistributionPlatform, DistributionResult}; pub use turbolift_internals::*; pub use turbolift_macros::*; diff --git a/turbolift_internals/src/kubernetes.rs b/turbolift_internals/src/kubernetes.rs index 3dfb0b89..3d3affe0 100644 --- a/turbolift_internals/src/kubernetes.rs +++ b/turbolift_internals/src/kubernetes.rs @@ -12,10 +12,17 @@ use crate::distributed_platform::{ const K8S_NAMESPACE: &str = "turbolift"; type ImageTag = String; +#[derive(Default)] pub struct K8s { pods: Vec, } +impl K8s { + pub fn new() -> K8s { + K8s { pods: Vec::new() } + } +} + #[async_trait] impl DistributionPlatform for K8s { async fn declare(&mut self, function_name: &str, project_tar: &[u8]) -> DistributionResult<()> {