3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-24 11:39:25 +01:00

relay: spawn servers, raise exportDB interval to 60; use main(irc)

This commit is contained in:
James Lu 2015-07-11 20:14:30 -07:00
parent 5d5f556ee3
commit e073f21417

View File

@ -21,11 +21,6 @@ def loadDB():
log.exception("Relay: failed to load links database %s" log.exception("Relay: failed to load links database %s"
", creating a new one in memory...", dbname) ", creating a new one in memory...", dbname)
db = {} db = {}
else:
for chanpair in db:
network, channel = chanpair
irc = utils.networkobjects[network]
irc.proto.joinClient(irc, irc.pseudoclient.uid, channel)
def exportDB(): def exportDB():
scheduler.enter(10, 1, exportDB) scheduler.enter(10, 1, exportDB)
@ -81,12 +76,17 @@ def destroy(irc, source, args):
else: else:
utils.msg(irc, source, 'Error: no such relay %r exists.' % channel) utils.msg(irc, source, 'Error: no such relay %r exists.' % channel)
def main(): def main(irc):
global scheduler global scheduler
scheduler = sched.scheduler() scheduler = sched.scheduler()
loadDB() loadDB()
scheduler.enter(10, 1, exportDB) scheduler.enter(60, 1, exportDB)
thread = threading.Thread(target=scheduler.run) thread = threading.Thread(target=scheduler.run)
thread.start() thread.start()
for chanpair in db:
main() network, channel = chanpair
ircobj = utils.networkobjects[network]
ircobj.proto.joinClient(ircobj, irc.pseudoclient.uid, channel)
for network, ircobj in utils.networkobjects.items():
if ircobj.name != irc.name:
irc.proto.spawnServer(irc, '%s.relay' % network)