Skip to content

Instantly share code, notes, and snippets.

@DingoEatingFuzz
Created April 3, 2019 16:16
Show Gist options
  • Save DingoEatingFuzz/569b8864e8a505f9d002727ab8de552f to your computer and use it in GitHub Desktop.
Save DingoEatingFuzz/569b8864e8a505f9d002727ab8de552f to your computer and use it in GitHub Desktop.
Nomad Community Call Wave Dem
use std::{thread, time};
use std::collections::LinkedList;
use std::f32;
use rand::random;
fn main() {
let two_pi = f32::consts::PI * 2.0;
let wait_duration = time::Duration::from_millis(500);
// Length of the list when wave as at 0
let baseline = 1500000.0;
// Max distance from baseline
let magnitude = 1000000.0;
// Number of ticks to make a full wave
let period = 50.0;
// Just a list used to take up memory
let mut list: LinkedList<f32> = LinkedList::new();
// Make sure the desired length can't go below 0
assert!(baseline > magnitude);
let mut tick = 0.0;
loop {
// Computed the desired length, based on the tick, baseline, and magnitude
let desired_len:i32 = (baseline + (tick / period * two_pi).sin() * magnitude) as i32;
// Figure out how many elements need to be added or removed
let delta:i32 = desired_len - (list.len() as i32);
println!("Tick: {}, Current Len: {}, Desired Len: {} Delta: {}", tick, list.len(), desired_len, delta);
if delta > 0 {
// Add things to the list
for _ in 1..delta {
list.push_back(random());
}
} else {
// Remove things from the list
let range = delta.abs();
for _ in 1..range {
list.pop_back();
}
}
thread::sleep(wait_duration);
// Increment tick but prevent it from going beyond the period value
tick = (tick + 1.0) % period;
}
}
job "wave" {
datacenters = ["dc1"]
update {
canary = 1
max_parallel = 2
min_healthy_time = "5s"
}
group "wave" {
count = 5
task "wave" {
driver = "raw_exec"
config {
command = "/Users/michael/lab/wave/target/debug/wave-0.1"
}
resources {
cpu = 250
memory = 128
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment