diff --git a/Cargo.lock b/Cargo.lock index ae555c45..5debe77e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2589,6 +2589,7 @@ dependencies = [ "plume-api 0.4.0", "plume-common 0.4.0", "plume-models 0.4.0", + "riker 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "rocket 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "rocket_contrib 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "rocket_csrf 0.1.0 (git+https://github.com/fdb-hiroshima/rocket_csrf?rev=29910f2829e7e590a540da3804336577b48c7b31)", diff --git a/Cargo.toml b/Cargo.toml index 3c16059b..582a1ce9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ heck = "0.3.0" lettre = "0.9.2" lettre_email = "0.9.2" num_cpus = "1.10" +riker = "0.4" rocket = "0.4.5" rocket_contrib = { version = "0.4.5", features = ["json"] } rocket_i18n = { git = "https://github.com/Plume-org/rocket_i18n", rev = "e922afa7c366038b3433278c03b1456b346074f2" } diff --git a/plume-models/src/search/searcher.rs b/plume-models/src/search/searcher.rs index dcd3529e..3abf2838 100644 --- a/plume-models/src/search/searcher.rs +++ b/plume-models/src/search/searcher.rs @@ -6,7 +6,7 @@ use chrono::{Datelike, Utc}; use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl}; use itertools::Itertools; use riker::actors::*; -use std::{cmp, fs::create_dir_all, io, path::Path, sync::Mutex}; +use std::{cmp, fs::create_dir_all, io, path::Path, sync::Arc, sync::Mutex}; use tantivy::{ collector::TopDocs, directory::MmapDirectory, schema::*, Index, IndexReader, IndexWriter, ReloadPolicy, TantivyError, Term, @@ -66,6 +66,12 @@ impl Receive for SearcherActor { } } +impl ActorFactoryArgs> for SearcherActor { + fn create_args(searcher: Arc) -> Self { + SearcherActor(Arc::try_unwrap(searcher).ok().unwrap()) + } +} + impl Searcher { /// Initializes a new `Searcher`, ready to be used by /// Plume. diff --git a/src/main.rs b/src/main.rs index 2b271b4e..41b18a1b 100755 --- a/src/main.rs +++ b/src/main.rs @@ -10,8 +10,14 @@ extern crate serde_json; #[macro_use] extern crate validator_derive; +extern crate riker; + use clap::App; -use plume_models::{db_conn::init_pool, migrations::IMPORTED_MIGRATIONS, search::Searcher, CONFIG}; +use plume_models::{ + db_conn::init_pool, migrations::IMPORTED_MIGRATIONS, search::Searcher, search::SearcherActor, + CONFIG, +}; +use riker::actors::*; use rocket_csrf::CsrfFairingBuilder; use scheduled_thread_pool::ScheduledThreadPool; use std::process::exit; @@ -77,8 +83,13 @@ Then try to restart Plume. ) } let workpool = ScheduledThreadPool::with_name("worker {}", num_cpus::get()); - let searcher = Arc::new(Searcher::new(dbpool.clone())); + + let sys = SystemBuilder::new().name("plume").create().unwrap(); + let _ = sys + .actor_of_args::("searcher-actor", searcher.clone()) + .unwrap(); + let commiter = searcher.clone(); workpool.execute_with_fixed_delay( Duration::from_secs(5),