Replaces the bench guild's scripts in the database with the given ones, spawns vm worker processes and waits for them to connect.
(
opts: FullFlowBenchOptions,
scripts: Vec<BenchScript>,
)
| 75 | /// Replaces the bench guild's scripts in the database with the given ones, |
| 76 | /// spawns vm worker processes and waits for them to connect. |
| 77 | pub async fn new( |
| 78 | opts: FullFlowBenchOptions, |
| 79 | scripts: Vec<BenchScript>, |
| 80 | ) -> anyhow::Result<Self> { |
| 81 | anyhow::ensure!( |
| 82 | !scripts.is_empty(), |
| 83 | "the full flow bench needs at least one script, events aren't dispatched to guilds without scripts" |
| 84 | ); |
| 85 | |
| 86 | let existing = opts.db.list_scripts(opts.guild_id).await?; |
| 87 | for script in existing { |
| 88 | opts.db.del_script(opts.guild_id, script.name).await?; |
| 89 | } |
| 90 | for script in scripts { |
| 91 | opts.db |
| 92 | .create_script( |
| 93 | opts.guild_id, |
| 94 | CreateScript { |
| 95 | name: script.name, |
| 96 | original_source: script.source, |
| 97 | enabled: true, |
| 98 | plugin_auto_update: None, |
| 99 | plugin_id: None, |
| 100 | plugin_version_number: None, |
| 101 | }, |
| 102 | ) |
| 103 | .await?; |
| 104 | } |
| 105 | |
| 106 | let worker_pool = VmWorkerPool::new(opts.launch_config); |
| 107 | |
| 108 | #[cfg(target_family = "unix")] |
| 109 | crate::worker_listener::listen_for_workers( |
| 110 | "/tmp/botloader_scheduler_workers", |
| 111 | worker_pool.clone(), |
| 112 | ) |
| 113 | .await; |
| 114 | |
| 115 | #[cfg(target_family = "windows")] |
| 116 | crate::worker_listener::listen_for_workers("localhost:7885", worker_pool.clone()).await; |
| 117 | |
| 118 | worker_pool.spawn_workers(None, opts.num_workers); |
| 119 | |
| 120 | // workers do their own startup (discord config fetch, db connect) before |
| 121 | // connecting back to us |
| 122 | while worker_pool.worker_statuses().len() < opts.num_workers { |
| 123 | tokio::time::sleep(Duration::from_millis(50)).await; |
| 124 | } |
| 125 | |
| 126 | let (cmd_manager, cmd_handle) = crate::command_manager::create_manager_pair( |
| 127 | opts.db.clone(), |
| 128 | opts.discord_config.clone(), |
| 129 | opts.logger.clone(), |
| 130 | ); |
| 131 | |
| 132 | let scheduler_config = Arc::new(SchedulerConfig { |
| 133 | broker_rpc_connect_adddr: String::new(), |
| 134 | integration_tests_guild: None, |
nothing calls this directly
no test coverage detected