"crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "crossbeam-utils"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
[[package]]
name = "crossbeam-utils"
version = "0.6.6"
"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "subprocess"
+version = "0.1.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
[[package]]
name = "syn"
version = "0.15.44"
"handlebars 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"simplelog 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "subprocess 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
"checksum copyless 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6ff9c56c9fb2a49c05ef0e431485a22400af20d33226dc0764d891d09e724127"
"checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1"
"checksum crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c8ec7fcd21571dc78f96cc96243cab8d8f035247c3efd16c687be154c3fa9efa"
+"checksum crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "677d453a17e8bd2b913fa38e8b9cf04bcdbb5be790aa294f2389661d72036015"
"checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6"
"checksum derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6d944ac6003ed268757ef1ee686753b57efc5fcf0ebe7b64c9fc81e7e32ff839"
"checksum derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a141330240c921ec6d074a3e188a7c7ef95668bb95e7d44fa0e5778ec2a7afe"
"checksum socket2 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "e8b74de517221a2cb01a53349cf54182acdc31a074727d3079068448c0676d85"
"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
"checksum string 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d24114bfcceb867ca7f71a0d3fe45d45619ec47a6fbfa98cb14e14250bfa5d6d"
+"checksum subprocess 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "28fc0f40f0c0da73339d347aa7d6d2b90341a95683a47722bc4eebed71ff3c00"
"checksum syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)" = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5"
"checksum syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf"
"checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f"
handlebars = "2.0"
log = "0.4"
simplelog = "0.7"
+subprocess = "0.1"
init_web_server(queue_actor.start());
- sys.run();
+ let _ = sys.run();
}
#[derive(Message)]
pub struct NewTask {
- pub id: String,
+ pub name: String,
pub parameters: HashMap<String, String>,
pub command: String,
}
pub cwd: String,
pub queue_actor: Addr<QueueActor>,
}
+
+#[derive(Message)]
+pub struct TaskCompleted {
+ pub command: String,
+ pub cwd: String,
+ pub queue_actor: Addr<QueueActor>,
+}
}
}
+
impl Handler<NewTask> for QueueActor {
type Result = ();
fn handle(&mut self, new_task: NewTask, _context: &mut Self::Context) {
- info!("Got new Task: {}", new_task.id);
+ info!("Got new Task: {}", new_task.name);
self.dispatch_task(new_task);
}
}
+
+impl Handler<TaskCompleted> for QueueActor {
+ type Result = ();
+
+ fn handle(&mut self, message: TaskCompleted, _context: &mut Self::Context) {
+ info!("Finished task: {}", message.command);
+ }
+}
+
+
impl QueueActor {
fn dispatch_task(&mut self, new_task: NewTask) {
let addr = self.own_addr.as_ref().unwrap().clone();
use ::actix::prelude::*;
use ::log::info;
+use ::subprocess::{Exec, Redirection, CaptureData, ExitStatus};
use crate::messages::*;
use crate::queue_actor::QueueActor;
fn handle(&mut self, task: StartTask, _context: &mut Self::Context) {
info!("Starting Task: {}", task.command);
+
+ let result = Exec::shell(task.command)
+ .cwd(task.cwd)
+ .stdout(Redirection::Pipe)
+ .stderr(Redirection::Pipe)
+ .capture();
+
+ let captured_data: CaptureData;
+
+ match result {
+ Ok(data) => {
+ captured_data = data;
+ }
+ Err(error) => {
+ info!("Error during task execution: {}", error);
+ return
+ },
+ }
+
+ match captured_data.exit_status {
+ ExitStatus::Exited(exit_code) => {
+ },
+ ExitStatus::Signaled(signal) => {
+ },
+ ExitStatus::Other(other) => {
+ },
+ ExitStatus::Undetermined => {
+ },
+ }
+
+ let output = captured_data.stdout_str();
+
+ info!("{}", output);
}
}
use ::actix::prelude::*;
-use ::actix_web::middleware::Logger;
use ::actix_web::*;
use ::log::info;
) -> Result<HttpResponse, HttpResponse> {
// Verify that the parameters match the required parameters in the template string
let params = query.into_inner();
- let webhook_id = path_info.into_inner();
+ let webhook_name = path_info.into_inner();
info!("");
- info!("Incoming webhook for \"{}\":", webhook_id);
- let command = verify_template_parameters("This is a test {{rofl}}".to_string(), ¶ms)?;
+ info!("Incoming webhook for \"{}\":", webhook_name);
+ let command = verify_template_parameters("ls {{rofl}}".to_string(), ¶ms)?;
- // Create a new task with the checked parameters and webhook id
+ // Create a new task with the checked parameters and webhook name
let new_task = NewTask {
- id: webhook_id,
+ name: webhook_name,
parameters: params,
command: command,
};
.data(AppState {
queue_actor: queue_actor.clone(),
})
- .wrap(Logger::default())
- .service(web::resource("/webhook/{webhook_id}").to(webhook))
+ .service(web::resource("/webhook/{webhook_name}").to(webhook))
})
.bind("127.0.0.1:8000")
.unwrap()