(&mut self, cmd: SchedulerCommand)
| 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 | )); |
no test coverage detected