You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
3.7 KiB
158 lines
3.7 KiB
#![cfg_attr(nightly, feature(int_error_matching))]
|
|
#![cfg_attr(nightly, feature(const_fn))]
|
|
#![cfg_attr(nightly, feature(maybe_uninit_ref))]
|
|
|
|
#![allow(dead_code)]
|
|
|
|
use tokio::{
|
|
select,
|
|
time::{
|
|
self,
|
|
Duration,
|
|
},
|
|
sync::{
|
|
mpsc,
|
|
},
|
|
task,
|
|
};
|
|
use lazy_static::lazy_static;
|
|
|
|
mod util;
|
|
use util::*;
|
|
|
|
mod log;
|
|
|
|
mod sys;
|
|
|
|
mod interval;
|
|
mod config;
|
|
|
|
mod hot;
|
|
|
|
mod context;
|
|
mod job;
|
|
|
|
//This is a test function, when we have a real job server, remove it.
|
|
async fn do_thing_every() -> Result<(mpsc::Sender<()>, task::JoinHandle<()>), Box<dyn std::error::Error>>
|
|
{
|
|
let mut interval = time::interval(Duration::from_secs(10));
|
|
|
|
let (tx, mut rx) = mpsc::channel(16);
|
|
|
|
let handle = tokio::spawn(async move {
|
|
println!("starting?");
|
|
|
|
loop {
|
|
let tick = interval.tick();
|
|
tokio::pin!(tick);
|
|
loop {
|
|
select!{
|
|
_ = &mut tick => {
|
|
// Do the things
|
|
println!("yes");
|
|
break;
|
|
}
|
|
_command = rx.recv() => {
|
|
// We got interrupt, interpret `command` here.
|
|
// `continue` to continue waiting on this interval, break to go to next, return to stop
|
|
println!("no");
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
Ok((tx, handle))
|
|
}
|
|
|
|
fn print_stats()
|
|
{
|
|
use recolored::Colorize;
|
|
lazy_static! {
|
|
static ref AUTHORS: String = env!("CARGO_PKG_AUTHORS").replace( ":", ", ");
|
|
|
|
};
|
|
|
|
#[cfg(debug_assertions)]
|
|
lazy_static!{
|
|
static ref BUILD_IDENT: recolored::ColoredString = "debug".bright_blue();
|
|
}
|
|
#[cfg(not(debug_assertions))]
|
|
lazy_static!{
|
|
static ref BUILD_IDENT: recolored::ColoredString = "release".bright_red();
|
|
}
|
|
|
|
#[allow(unused_imports)]
|
|
use std::ops::Deref;
|
|
status!("This is the lolicron daemon version {} by {} ({} build)", env!("CARGO_PKG_VERSION"), &AUTHORS[..], BUILD_IDENT.deref());
|
|
status!("---");
|
|
status!("Compiled with ({}, {}, {}, {}):", "on".bright_red(), "default on".red(), "off".bright_blue(), "default off".blue());
|
|
|
|
#[cfg(nightly)] status!(" +nightly".bright_red());
|
|
#[cfg(debug_assertions)] status!(" +debug_assertions".red());
|
|
|
|
status!("features:");
|
|
|
|
#[cfg(feature="threaded")] status!(" +threaded".red());
|
|
#[cfg(not(feature="threaded"))] status!(" -threaded".bright_blue());
|
|
|
|
#[cfg(feature="watcher")] status!(" +watcher".red());
|
|
#[cfg(not(feature="watcher"))] status!(" -watcher".bright_blue());
|
|
|
|
#[cfg(feature="debug_logger")] status!(" +debug_logger".red());
|
|
#[cfg(not(feature="debug_logger"))] status!(" -debug_logger".bright_blue());
|
|
|
|
#[cfg(feature="watcher_unlimited")] status!(" +watcher_unlimited".bright_red());
|
|
#[cfg(not(feature="watcher_unlimited"))] status!(" -watcher_unlimited".blue());
|
|
|
|
#[cfg(feature="watcher_timeout")] status!(" +watcher_timeout".red());
|
|
#[cfg(not(feature="watcher_timeout"))] status!(" -watcher_timeout".bright_blue());
|
|
|
|
status!("");
|
|
|
|
config::build::stat();
|
|
|
|
status!("GPl'd with <3");
|
|
status!("Please enjoy");
|
|
|
|
status!("---");
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
log::init(log::Level::Debug);
|
|
|
|
debug!("Logger initialised"); //TODO: Parse config first
|
|
print_stats();
|
|
|
|
#[cfg(feature="watcher")]
|
|
{
|
|
let oneesan = hot::watch(".");
|
|
|
|
{
|
|
let mut recv = oneesan.hook("src/main.rs", hot::filter::ALL).await;
|
|
while let Some(event) = recv.recv().await
|
|
{
|
|
important!("Got ev {:?}", event);
|
|
break;
|
|
}
|
|
}
|
|
|
|
oneesan.shutdown().await.expect("oneesan panic");
|
|
}
|
|
|
|
println!("{:?}", config::parse_global_single("example.rori").await.expect("Waaaaaah"));
|
|
|
|
//let (mut tx, h) = do_thing_every().await?;
|
|
|
|
// loop {
|
|
// time::delay_for(Duration::from_secs(6)).await;
|
|
// tx.send(()).await?;
|
|
// }
|
|
// h.await?;
|
|
|
|
Ok(())
|
|
}
|