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

Method handle_scheduler_command

components/scheduler/src/scheduler.rs:196–284  ·  view source on GitHub ↗
(&mut self, cmd: SchedulerCommand)

Source from the content-addressed store, hash-verified

194 }
195
196 async fn handle_scheduler_command(&mut self, cmd: SchedulerCommand) {
197 match cmd {
198 // we shut down all previously running workers when a new broker connects
199 // this is because we could be out of sync otherwise and running guilds we shouldn't run
200 SchedulerCommand::BrokerHello(d) => {
201 info!("new broker connected");
202 self.shutdown_all();
203
204 self.pending_starts = Vec::new();
205
206 // start all the workers we can
207 for g in d.connected_guilds {
208 if !self.try_unsuspend_guild(g) {
209 continue;
210 }
211
212 let worker = self.get_or_start_guild(g);
213 if worker.tx.is_none() {
214 // this worker shutting down, schedule it for restart
215 self.pending_starts.push(g)
216 }
217 }
218 }
219
220 SchedulerCommand::BrokerDisconnected => {
221 self.shutdown_all();
222 }
223 SchedulerCommand::BrokerConnected => {}
224 SchedulerCommand::DiscordEvent(evt) => {
225 crate::dispatch_metrics::record_stage("scheduler_recv", "discord", evt.timestamp);
226
227 if !self.try_unsuspend_guild(evt.guild_id) {
228 return;
229 }
230
231 if let DiscordEventData::GuildDelete(_) = evt.event {
232 if let Some(worker) = self.guilds.get_mut(&evt.guild_id) {
233 // this will signal the worker to shut down
234 if let Some(tx) = worker.tx.take() {
235 let _ = tx.send(GuildCommand::Shutdown);
236 }
237 }
238 } else {
239 self.send_or_queue_broker_evt(evt)
240 }
241 }
242 SchedulerCommand::Shutdown => {
243 panic!("should be handled by caller")
244 }
245 SchedulerCommand::ReloadGuildScripts(guild_id) => {
246 // reset the blacklisted state
247 if self.try_unsuspend_guild(guild_id) {
248 self.get_or_start_guild(guild_id);
249 } else {
250 self.logger.log(LogEntry::error(
251 guild_id,
252 "can't unsuspend your guild yet, please wait 10 minutes".to_owned(),
253 ));

Callers 1

runMethod · 0.80

Calls 10

record_stageFunction · 0.85
errorFunction · 0.85
shutdown_allMethod · 0.80
try_unsuspend_guildMethod · 0.80
get_or_start_guildMethod · 0.80
logMethod · 0.80
worker_statusesMethod · 0.80
sendMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected