Skip to content

Commit

Permalink
workers: remove test job
Browse files Browse the repository at this point in the history
  • Loading branch information
barzamin committed Mar 29, 2019
1 parent 4a02840 commit d7120dc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 53 deletions.
28 changes: 3 additions & 25 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use rocket::config::Config;
use rocket::Rocket;
use rocket_slog::SlogFairing;
use slog::Drain;
use slog::{slog_debug, slog_o, slog_warn};
use slog_scope::{debug, warn};
use slog::{slog_debug, slog_o, slog_warn, slog_info};
use slog_scope::{debug, warn, info};
use std::env;

lazy_static! {
Expand Down Expand Up @@ -87,31 +87,9 @@ fn rocket_load_config() -> Config {

pub fn app(db: db::Pool, logger: slog::Logger) -> Rocket {
// initialize the worker queues
debug!("starting worker queues");
info!("starting worker queues");
workers::init(db.clone());

{
use diesel::prelude::*;
let conn = db.get().unwrap();

use crate::db::models::NewJobRecord;
let r = NewJobRecord::on_queue(
workers::TestJob {
msg: "bengis".to_string(),
},
"default_queue",
)
.unwrap();
debug!("injecting test job");
diesel::insert_into(db::schema::jobs::table)
.values(&r)
.execute(&conn)
.unwrap();
debug!("done injecting test job");

// println!("{:?}", r);
}

rocket::custom(rocket_load_config()) // use our own config loading which turns off Rocket's built-in logging.
.mount("/", routes::ui::routes())
.mount("/", routes::ap::routes())
Expand Down
28 changes: 0 additions & 28 deletions src/workers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,9 @@ use turnstile::{ExecutionContract, Job, Perform, Worker};
const BATCH_SIZE: i64 = 10;
const CHECK_PERIOD: Duration = Duration::from_secs(1); // 1/(1 hz)

#[derive(Serialize, Deserialize)]
pub struct TestJob {
pub msg: String,
}

impl Job for TestJob {
fn kind() -> &'static str {
"test_job"
}

fn should_run(&self) -> bool {
true
}

fn execution_contract(&self) -> ExecutionContract {
ExecutionContract::immediate_fail()
}
}

impl Perform for TestJob {
fn perform(&self) -> Result<(), Box<Error>> {
info!("+++++++ {a} {a} {a} {a} +++++++", a = &self.msg);
Ok(())
}
}

pub fn init(pool: Pool) {
let mut worker = Worker::new();

worker.register_job::<TestJob>();

thread::Builder::new()
.name("job_collector".to_string())
.spawn(move || loop {
Expand Down

0 comments on commit d7120dc

Please sign in to comment.