def run(self) -> None: """Start integration with server. Based on the settings done in initialization, this will... - start workers - load plugin modules - add scheduled jobs and start scheduler - connect to server - stop workers and scheduler when connection is gone """ # Setup required workers self.worker = ThreadPoolExecutor(max_workers=self.max_workers) \ if self.max_workers else None self.message_worker = ThreadExecutor() # Load plugins self.load_plugins() # Set scheduled job self.add_schedule_jobs(self.schedules) self.scheduler.start() try: self.connect() except Exception as e: logging.error("Error occurred while bot interaction", e) finally: self.stop()
def test_valid(self): base_impl = create_concrete_class()(None, max_workers=3) base_impl.message_worker = ThreadExecutor() with patch.object(base_impl.message_worker, 'submit', return_value=Future()): base_impl.enqueue_sending_message(lambda _: "dummy") assert_that(base_impl.message_worker.submit.call_count) \ .is_equal_to(1)