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.

171 lines
4.2 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".red(), "off".bright_blue(), "default".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>> {
let child = sys::fork::detach_closure(None, None, |parent| {
println!("Parent: {:?}, us: {}", parent, sys::get_pid());
std::thread::sleep_ms(3000);
println!("Exiting child");
}).await?;
println!("Child: {:?}", child);
println!("Waitpid: {:?}", child.wait().await?);
// end test
log::init(log::Level::Debug);
log::Logger::global().add_hook(log::custom::LogFileHook::new(log::Level::Debug, "test.log", "test.err.log", false));
debug!("Logger initialised"); //TODO: Parse config first
print_stats();
//debug!("{:?}",sys::user::get_users());
#[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(())
}