MCPcopy Create free account
hub / github.com/Botloader/botloader / run

Function run

components/vmworker/src/lib.rs:17–72  ·  view source on GitHub ↗
(config: WorkerConfig)

Source from the content-addressed store, hash-verified

15mod metrics_forwarder;
16
17pub async fn run(config: WorkerConfig) -> Result<(), Box<dyn std::error::Error>> {
18 common::setup_tracing(&config.common, "vmworker");
19
20 let discord_config = common::fetch_discord_config(config.common.discord_token.clone())
21 .await
22 .expect("failed fetching discord config");
23
24 info!("worker starting");
25
26 #[cfg(target_family = "unix")]
27 let (scheduler_tx, scheduler_rx) =
28 connect_scheduler("/tmp/botloader_scheduler_workers", config.worker_id).await;
29
30 #[cfg(target_family = "windows")]
31 let (scheduler_tx, scheduler_rx) = connect_scheduler("localhost:7885", config.worker_id).await;
32
33 metrics::set_global_recorder(metrics_forwarder::MetricsForwarder {
34 tx: scheduler_tx.clone(),
35 })
36 .expect("set metrics recorder");
37
38 let postgres_store = Db::new_with_url(&config.common.database_url).await.unwrap();
39
40 // suppress signals for now
41 // TODO: remove this? do we need signals here?
42 // ideally we wanna manage this through the parent
43 tokio::spawn(common::shutdown::wait_shutdown_signal());
44
45 let logger = {
46 let builder =
47 guild_logger::GuildLoggerBuilder::new().add_backend(Arc::new(GuildLogForwarder {
48 tx: scheduler_tx.clone(),
49 }));
50
51 builder.run()
52 };
53
54 let broker_client = dbrokerapi::state_client::Client::new(config.broker_api_addr);
55
56 vm::init_v8_platform();
57
58 let worker = Worker::new(
59 scheduler_rx,
60 scheduler_tx,
61 postgres_store,
62 logger,
63 discord_config,
64 config.common.user_script_http_proxy.clone(),
65 broker_client,
66 );
67
68 worker.run().await;
69 info!("worker shutting down");
70
71 Ok(())
72}
73
74#[derive(Clone, clap::Parser)]

Callers

nothing calls this directly

Calls 7

setup_tracingFunction · 0.85
fetch_discord_configFunction · 0.85
connect_schedulerFunction · 0.85
wait_shutdown_signalFunction · 0.85
init_v8_platformFunction · 0.85
add_backendMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected