move PoolHook registrations to start.py

This commit is contained in:
jesopo 2019-10-10 13:58:45 +01:00
parent e624292608
commit 1c792f0194
2 changed files with 9 additions and 7 deletions

View file

@ -36,7 +36,7 @@ class ListLambdaPollHook(PollHook.PollHook):
class Bot(object): class Bot(object):
def __init__(self, directory, args, cache, config, database, events, def __init__(self, directory, args, cache, config, database, events,
exports, log, modules, timers, lock_file): exports, log, modules, timers):
self.directory = directory self.directory = directory
self.args = args self.args = args
self.cache = cache self.cache = cache
@ -68,11 +68,7 @@ class Bot(object):
self._read_thread = None self._read_thread = None
self._write_thread = None self._write_thread = None
self._poll_timeouts = [] # typing.List[PollHook] self._poll_timeouts = [] # typing.List[PollHook.PollHook]
self._poll_timeouts.append(self._timers)
self._poll_timeouts.append(self.cache)
self._poll_timeouts.append(lock_file)
self._poll_timeouts.append(ListLambdaPollHook( self._poll_timeouts.append(ListLambdaPollHook(
lambda: self.servers.values(), lambda: self.servers.values(),
lambda server: server.until_read_timeout())) lambda server: server.until_read_timeout()))
@ -84,6 +80,9 @@ class Bot(object):
self._poll_timeouts.append(ListLambdaPollHook( self._poll_timeouts.append(ListLambdaPollHook(
lambda: self.servers.values(), self._throttle_timeout)) lambda: self.servers.values(), self._throttle_timeout))
def add_poll_hook(self, hook: PollHook.PollHook):
self._poll_timeouts.append(hook)
def _throttle_timeout(self, server: IRCServer.Server): def _throttle_timeout(self, server: IRCServer.Server):
if server.socket.waiting_throttled_send(): if server.socket.waiting_throttled_send():
return server.socket.send_throttle_timeout() return server.socket.send_throttle_timeout()

View file

@ -106,7 +106,10 @@ modules = ModuleManager.ModuleManager(events, exports, timers, config, log,
module_directories) module_directories)
bot = IRCBot.Bot(directory, args, cache, config, database, events, bot = IRCBot.Bot(directory, args, cache, config, database, events,
exports, log, modules, timers, lock_file) exports, log, modules, timers)
bot.add_poll_hook(cache)
bot.add_poll_hook(lock_file)
bot.add_poll_hook(timers)
if args.module: if args.module:
definition = modules.find_module(args.module) definition = modules.find_module(args.module)