mirror of
https://github.com/jlu5/PyLink.git
synced 2025-05-06 14:47:25 +02:00
relay/world: remove need for world.schedulers
This commit is contained in:
parent
270bdcc79a
commit
59c9b127a3
@ -21,7 +21,9 @@ spawnlocks = defaultdict(threading.RLock)
|
|||||||
spawnlocks_servers = defaultdict(threading.RLock)
|
spawnlocks_servers = defaultdict(threading.RLock)
|
||||||
savecache = ExpiringDict(max_len=5, max_age_seconds=10)
|
savecache = ExpiringDict(max_len=5, max_age_seconds=10)
|
||||||
killcache = ExpiringDict(max_len=5, max_age_seconds=10)
|
killcache = ExpiringDict(max_len=5, max_age_seconds=10)
|
||||||
relay_started = True
|
|
||||||
|
exportdb_scheduler = None
|
||||||
|
exportdb_event = None
|
||||||
|
|
||||||
dbname = utils.getDatabaseName('pylinkrelay')
|
dbname = utils.getDatabaseName('pylinkrelay')
|
||||||
|
|
||||||
@ -42,24 +44,26 @@ def initializeAll(irc):
|
|||||||
|
|
||||||
def main(irc=None):
|
def main(irc=None):
|
||||||
"""Main function, called during plugin loading at start."""
|
"""Main function, called during plugin loading at start."""
|
||||||
global relay_started
|
|
||||||
relay_started = True
|
|
||||||
loadDB()
|
loadDB()
|
||||||
world.schedulers['relaydb'] = scheduler = sched.scheduler()
|
|
||||||
scheduler.enter(30, 1, exportDB, argument=(True,))
|
global exportdb_scheduler, exportdb_event
|
||||||
|
exportdb_scheduler = sched.scheduler()
|
||||||
|
exportdb_event = exportdb_scheduler.enter(30, 1, exportDB, argument=(True,))
|
||||||
|
|
||||||
# Thread this because exportDB() queues itself as part of its
|
# Thread this because exportDB() queues itself as part of its
|
||||||
# execution, in order to get a repeating loop.
|
# execution, in order to get a repeating loop.
|
||||||
thread = threading.Thread(target=scheduler.run)
|
thread = threading.Thread(target=exportdb_scheduler.run)
|
||||||
thread.daemon = True
|
thread.daemon = True
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
if irc is not None:
|
if irc is not None:
|
||||||
for ircobj in world.networkobjects.values():
|
for ircobj in world.networkobjects.values():
|
||||||
initializeAll(ircobj)
|
initializeAll(ircobj)
|
||||||
|
|
||||||
def die(sourceirc):
|
def die(sourceirc):
|
||||||
"""Deinitialize PyLink Relay by quitting all relay clients."""
|
"""Deinitialize PyLink Relay by quitting all relay clients and saving the
|
||||||
global relay_started
|
relay DB."""
|
||||||
relay_started = False
|
|
||||||
for irc in world.networkobjects.values():
|
for irc in world.networkobjects.values():
|
||||||
for user in irc.users.copy():
|
for user in irc.users.copy():
|
||||||
if isRelayClient(irc, user):
|
if isRelayClient(irc, user):
|
||||||
@ -70,6 +74,12 @@ def die(sourceirc):
|
|||||||
relayservers.clear()
|
relayservers.clear()
|
||||||
relayusers.clear()
|
relayusers.clear()
|
||||||
|
|
||||||
|
exportDB(reschedule=False)
|
||||||
|
|
||||||
|
# Stop all scheduled DB exports
|
||||||
|
global exportdb_scheduler, exportdb_event
|
||||||
|
exportdb_scheduler.cancel(exportdb_event)
|
||||||
|
|
||||||
def normalizeNick(irc, netname, nick, separator=None, uid=''):
|
def normalizeNick(irc, netname, nick, separator=None, uid=''):
|
||||||
"""Creates a normalized nickname for the given nick suitable for
|
"""Creates a normalized nickname for the given nick suitable for
|
||||||
introduction to a remote network (as a relay client)."""
|
introduction to a remote network (as a relay client)."""
|
||||||
@ -143,9 +153,9 @@ def loadDB():
|
|||||||
def exportDB(reschedule=False):
|
def exportDB(reschedule=False):
|
||||||
"""Exports the relay database, optionally creating a loop to do this
|
"""Exports the relay database, optionally creating a loop to do this
|
||||||
automatically."""
|
automatically."""
|
||||||
scheduler = world.schedulers.get('relaydb')
|
global exportdb_scheduler, exportdb_event
|
||||||
if reschedule and scheduler and relay_started:
|
if reschedule and exportdb_scheduler:
|
||||||
scheduler.enter(30, 1, exportDB, argument=(True,))
|
exportdb_event = exportdb_scheduler.enter(30, 1, exportDB, argument=(True,))
|
||||||
log.debug("Relay: exporting links database to %s", dbname)
|
log.debug("Relay: exporting links database to %s", dbname)
|
||||||
with open(dbname, 'wb') as f:
|
with open(dbname, 'wb') as f:
|
||||||
pickle.dump(db, f, protocol=4)
|
pickle.dump(db, f, protocol=4)
|
||||||
|
1
world.py
1
world.py
@ -19,7 +19,6 @@ global commands, hooks
|
|||||||
commands = defaultdict(list)
|
commands = defaultdict(list)
|
||||||
hooks = defaultdict(list)
|
hooks = defaultdict(list)
|
||||||
networkobjects = {}
|
networkobjects = {}
|
||||||
schedulers = {}
|
|
||||||
plugins = {}
|
plugins = {}
|
||||||
whois_handlers = []
|
whois_handlers = []
|
||||||
started = threading.Event()
|
started = threading.Event()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user