Add job flags
This commit is contained in:
+23
-1
@@ -9,8 +9,22 @@ pub struct Args {
|
||||
#[structopt(short, help = "A list of domains that should be whitelisted")]
|
||||
whitelists: Vec<String>,
|
||||
|
||||
#[structopt(short, help = "Undo whitelisting or blocking these domains")]
|
||||
#[structopt(short, long, help = "Undo whitelisting or blocking domains")]
|
||||
undo: bool,
|
||||
|
||||
#[structopt(
|
||||
short,
|
||||
long,
|
||||
help = "Only process background jobs, do not start the relay server"
|
||||
)]
|
||||
jobs_only: bool,
|
||||
|
||||
#[structopt(
|
||||
short,
|
||||
long,
|
||||
help = "Only run the relay server, do not process background jobs"
|
||||
)]
|
||||
no_jobs: bool,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
@@ -29,4 +43,12 @@ impl Args {
|
||||
pub fn undo(&self) -> bool {
|
||||
self.undo
|
||||
}
|
||||
|
||||
pub fn jobs_only(&self) -> bool {
|
||||
self.jobs_only
|
||||
}
|
||||
|
||||
pub fn no_jobs(&self) -> bool {
|
||||
self.no_jobs
|
||||
}
|
||||
}
|
||||
|
||||
+25
-1
@@ -1,3 +1,4 @@
|
||||
use actix::Arbiter;
|
||||
use actix_web::{
|
||||
http::header::{ContentType, Expires},
|
||||
middleware::Logger,
|
||||
@@ -92,6 +93,12 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||
|
||||
let args = Args::new();
|
||||
|
||||
if args.jobs_only() && args.no_jobs() {
|
||||
return Err(anyhow::Error::msg(
|
||||
"Either the server or the jobs must be run",
|
||||
));
|
||||
}
|
||||
|
||||
if !args.blocks().is_empty() || !args.whitelists().is_empty() {
|
||||
if args.undo() {
|
||||
db.remove_blocks(args.blocks()).await?;
|
||||
@@ -110,9 +117,26 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||
|
||||
let job_server = create_server(db.clone());
|
||||
|
||||
if args.jobs_only() {
|
||||
for _ in 0..num_cpus::get() {
|
||||
let state = state.clone();
|
||||
let job_server = job_server.clone();
|
||||
|
||||
Arbiter::new().exec_fn(move || {
|
||||
create_workers(state, job_server);
|
||||
});
|
||||
}
|
||||
actix_rt::signal::ctrl_c().await?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let no_jobs = args.no_jobs();
|
||||
|
||||
let bind_address = config.bind_address();
|
||||
HttpServer::new(move || {
|
||||
create_workers(state.clone(), job_server.clone());
|
||||
if !no_jobs {
|
||||
create_workers(state.clone(), job_server.clone());
|
||||
}
|
||||
|
||||
App::new()
|
||||
.wrap(Logger::default())
|
||||
|
||||
+2
-2
@@ -9,7 +9,7 @@ use futures::{
|
||||
use log::{debug, error, info, warn};
|
||||
use std::sync::Arc;
|
||||
|
||||
async fn handle_notification(state: &State, notif: Notification) {
|
||||
async fn handle_notification(state: State, notif: Notification) {
|
||||
match notif.channel() {
|
||||
"new_blocks" => {
|
||||
info!("Caching block of {}", notif.payload());
|
||||
@@ -88,7 +88,7 @@ pub fn spawn(state: State, config: &crate::config::Config) -> Result<(), MyError
|
||||
});
|
||||
|
||||
while let Some(n) = stream.next().await {
|
||||
handle_notification(&state, n).await;
|
||||
actix::spawn(handle_notification(state.clone(), n));
|
||||
}
|
||||
|
||||
drop(client);
|
||||
|
||||
Reference in New Issue
Block a user