-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstandalone.rs
55 lines (41 loc) · 1.38 KB
/
standalone.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! Run in standalone mode
use std::sync::Arc;
use std::thread;
use tokio::runtime::Builder;
use crate::config;
use crate::database::MonitorDb;
use crate::tasks::TaskManager;
use crate::{flash, init, webserver, Args, HARDWARE};
pub fn run_standalone_mode(db: Arc<MonitorDb>, cli_args: Arc<Args>) {
init::check_uninit(db.clone());
config::load_app_config_from_db(&db);
init::initialize_statics();
let mut hardware = HARDWARE.lock().unwrap();
init::init_hardware(db.clone(), &mut hardware);
init::init_testprograms(db.clone(), &hardware);
flash::flash_testbinaries(db.clone(), &hardware);
drop(hardware);
// Create async runtime
let rt = Arc::new(
Builder::new_current_thread()
.enable_io()
.enable_time()
.build()
.unwrap(),
);
let (task_manager, task_scheduler) = TaskManager::new(db.clone(), rt.clone());
let async_tread = thread::spawn(move || {
rt.block_on(async {
tokio::spawn(async {
tokio::signal::ctrl_c()
.await
.expect("Failed to receive shutdown event");
crate::shutdown_application();
});
webserver::web_server(db, task_manager, cli_args).await;
});
});
task_scheduler.run();
// Wait for async thread to shutdown
async_tread.join().unwrap();
}