Prototype the travis-ci processor pushing directly into the tasks.for_auction channel
This doesn't help too terribly much at this point, but at least it's a means of getting a .travis-ci.yml into the system
This commit is contained in:
parent
cba11b7e82
commit
a32e28d2d2
|
@ -1491,7 +1491,11 @@ dependencies = [
|
||||||
name = "processor-travis-ci"
|
name = "processor-travis-ci"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"actix 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"otto-eventbus 0.1.0",
|
||||||
|
"pretty_env_logger 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde_yaml 0.8.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_yaml 0.8.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -35,6 +35,10 @@ pub struct EventBusClient {
|
||||||
id: &'static str,
|
id: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Message)]
|
||||||
|
#[rtype(result = "()")]
|
||||||
|
pub struct Disconnect;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of the Debug trait so that the EventBusClient can be included
|
* Implementation of the Debug trait so that the EventBusClient can be included
|
||||||
* in logging statements and print each instance's `id`
|
* in logging statements and print each instance's `id`
|
||||||
|
@ -45,10 +49,6 @@ impl std::fmt::Debug for EventBusClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait EventDispatch<T> {
|
|
||||||
fn dispatch(&self, payload: T);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* connect will create begin the connection process and start the EventBusClient
|
* connect will create begin the connection process and start the EventBusClient
|
||||||
* actor.
|
* actor.
|
||||||
|
@ -96,7 +96,6 @@ impl EventBusClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//impl Actor<dyn EventDispatch> for EventBusClient {
|
|
||||||
impl Actor for EventBusClient {
|
impl Actor for EventBusClient {
|
||||||
type Context = Context<Self>;
|
type Context = Context<Self>;
|
||||||
|
|
||||||
|
@ -119,6 +118,24 @@ impl Actor for EventBusClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Handler<Disconnect> for EventBusClient {
|
||||||
|
type Result = ();
|
||||||
|
|
||||||
|
fn handle(&mut self, _: Disconnect, ctx: &mut Context<Self>) {
|
||||||
|
ctx.stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Handler<InputMessage> for EventBusClient {
|
||||||
|
type Result = ();
|
||||||
|
|
||||||
|
fn handle(&mut self, input: InputMessage, _ctx: &mut Context<Self>) {
|
||||||
|
self.sink
|
||||||
|
.write(Message::Text(serde_json::to_string(&input).unwrap()))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Handler<OutputMessage> for EventBusClient {
|
impl Handler<OutputMessage> for EventBusClient {
|
||||||
type Result = ();
|
type Result = ();
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,18 @@ pub struct Meta {
|
||||||
pub ts: DateTime<Utc>,
|
pub ts: DateTime<Utc>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Meta {
|
||||||
|
/**
|
||||||
|
* Construct a Meta struct with the current time
|
||||||
|
*/
|
||||||
|
pub fn new(channel: String) -> Self {
|
||||||
|
Meta {
|
||||||
|
channel: channel,
|
||||||
|
ts: Utc::now(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Output enums are all meant to capture the types of messages which can be received from the
|
* The Output enums are all meant to capture the types of messages which can be received from the
|
||||||
* eventbus.
|
* eventbus.
|
||||||
|
@ -158,4 +170,10 @@ mod test {
|
||||||
assert_eq!(m.channel, "");
|
assert_eq!(m.channel, "");
|
||||||
assert!(m.ts < Utc::now());
|
assert!(m.ts < Utc::now());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_new_meta() {
|
||||||
|
let m = Meta::new("foo".to_string());
|
||||||
|
assert_eq!(m.channel, "foo");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,14 @@ serde = "~1.0.103"
|
||||||
serde_json = "~1.0.0"
|
serde_json = "~1.0.0"
|
||||||
serde_yaml = "~0.8.11"
|
serde_yaml = "~0.8.11"
|
||||||
|
|
||||||
|
actix = "~0.9.0"
|
||||||
|
log = "~0.4.8"
|
||||||
|
pretty_env_logger = "~0.3.1"
|
||||||
|
|
||||||
# Handling command line options
|
# Handling command line options
|
||||||
clap = { version = "~2.33.0", features = ["yaml"] }
|
clap = { version = "~2.33.0", features = ["yaml"] }
|
||||||
|
|
||||||
# Needed for generating uuids
|
# Needed for generating uuids
|
||||||
uuid = { version = "~0.8.1", features = ["serde", "v4"] }
|
uuid = { version = "~0.8.1", features = ["serde", "v4"] }
|
||||||
|
|
||||||
|
otto-eventbus = { path = "../../eventbus" }
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
|
extern crate actix;
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
|
extern crate pretty_env_logger;
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
extern crate serde_yaml;
|
extern crate serde_yaml;
|
||||||
extern crate uuid;
|
extern crate uuid;
|
||||||
|
|
||||||
use clap::{Arg, App};
|
use actix::*;
|
||||||
|
use clap::{App, Arg};
|
||||||
|
use log::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_yaml::Value;
|
use serde_yaml::Value;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
@ -11,31 +15,35 @@ use uuid::Uuid;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
|
use otto_eventbus::client::*;
|
||||||
|
use otto_eventbus::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
pretty_env_logger::init();
|
||||||
|
|
||||||
let matches = App::new("travis processor")
|
let matches = App::new("travis processor")
|
||||||
.arg(Arg::with_name("filename")
|
.arg(
|
||||||
.short("f")
|
Arg::with_name("filename")
|
||||||
.long("filename")
|
.short("f")
|
||||||
.value_name("FILE")
|
.long("filename")
|
||||||
.required(true)
|
.value_name("FILE")
|
||||||
.help("File")
|
.required(true)
|
||||||
.takes_value(true))
|
.help("File")
|
||||||
.get_matches();
|
.takes_value(true),
|
||||||
|
)
|
||||||
|
.get_matches();
|
||||||
let filename = matches.value_of("filename").unwrap_or(".travis-ci.yml");
|
let filename = matches.value_of("filename").unwrap_or(".travis-ci.yml");
|
||||||
let contents = fs::read_to_string(filename).expect("Something went wrong reading the file");
|
let contents = fs::read_to_string(filename).expect("Something went wrong reading the file");
|
||||||
let pipeline = serde_yaml::from_str::<TravisConfig>(&contents)
|
let pipeline = serde_yaml::from_str::<TravisConfig>(&contents)
|
||||||
.expect("Failed to deserialize the yaml file into a TravisConfig");
|
.expect("Failed to deserialize the yaml file into a TravisConfig");
|
||||||
|
|
||||||
let mut output = PipelineManifest {
|
let mut output = PipelineManifest { tasks: vec![] };
|
||||||
tasks: vec![],
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut caps = HashMap::new();
|
let mut caps = HashMap::new();
|
||||||
|
|
||||||
if pipeline.sudo {
|
if pipeline.sudo {
|
||||||
caps.insert("docker_run".to_string(), Value::Bool(false));
|
caps.insert("docker_run".to_string(), Value::Bool(false));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
caps.insert("docker_run".to_string(), Value::Bool(true));
|
caps.insert("docker_run".to_string(), Value::Bool(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,14 +63,16 @@ fn main() {
|
||||||
for script in pipeline.script.iter() {
|
for script in pipeline.script.iter() {
|
||||||
let mut data = HashMap::new();
|
let mut data = HashMap::new();
|
||||||
data.insert("script".to_string(), Value::String(script.to_string()));
|
data.insert("script".to_string(), Value::String(script.to_string()));
|
||||||
data.insert("timeout_s".to_string(), Value::Number(serde_yaml::Number::from(300)));
|
data.insert(
|
||||||
|
"timeout_s".to_string(),
|
||||||
|
Value::Number(serde_yaml::Number::from(300)),
|
||||||
|
);
|
||||||
data.insert("env".to_string(), Value::Null);
|
data.insert("env".to_string(), Value::Null);
|
||||||
task.ops.push(Op {
|
task.ops.push(Op {
|
||||||
id: Uuid::new_v4().to_string(),
|
id: Uuid::new_v4().to_string(),
|
||||||
op_type: OpType::RunProcess,
|
op_type: OpType::RunProcess,
|
||||||
data
|
data,
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
task.ops.push(Op {
|
task.ops.push(Op {
|
||||||
|
@ -74,7 +84,33 @@ fn main() {
|
||||||
|
|
||||||
output.tasks.push(task);
|
output.tasks.push(task);
|
||||||
|
|
||||||
println!("{}", serde_yaml::to_string(&output).expect("Failed to serialize manifest"));
|
info!(
|
||||||
|
"{}",
|
||||||
|
serde_yaml::to_string(&output).expect("Failed to serialize manifest")
|
||||||
|
);
|
||||||
|
|
||||||
|
let sys = System::new("name");
|
||||||
|
Arbiter::spawn(async {
|
||||||
|
let client = connect("http://127.0.0.1:8000/ws/", "processor-travis-ci").await;
|
||||||
|
info!("Client created: {:?}", client);
|
||||||
|
|
||||||
|
let input = InputMessage {
|
||||||
|
meta: Meta::new("tasks.for_auction".to_string()),
|
||||||
|
msg: Input::Publish {
|
||||||
|
payload: serde_json::to_value(output).unwrap(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
client.do_send(input);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Disconnecting as soon as we send Input doesn't work well, because the client seems to
|
||||||
|
* terminate before it can actually send messages over.
|
||||||
|
*/
|
||||||
|
//client.do_send(Disconnect {});
|
||||||
|
//info!("Disconnected");
|
||||||
|
//System::current().stop();
|
||||||
|
});
|
||||||
|
sys.run().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Serialize)]
|
#[derive(Deserialize, Debug, Serialize)]
|
||||||
|
|
Loading…
Reference in New Issue