mirror of
https://github.com/jlu5/PyLink.git
synced 2025-02-17 14:01:03 +01:00
relay: hack in utils.schedulers so that exportDB only gets queued once globally
Previously, exportDB would be queued once by every IRC object, which was the wrong behavior!
This commit is contained in:
parent
e073f21417
commit
450584b963
@ -22,9 +22,9 @@ def loadDB():
|
|||||||
", creating a new one in memory...", dbname)
|
", creating a new one in memory...", dbname)
|
||||||
db = {}
|
db = {}
|
||||||
|
|
||||||
def exportDB():
|
def exportDB(scheduler):
|
||||||
scheduler.enter(10, 1, exportDB)
|
scheduler.enter(60, 1, exportDB, argument=(scheduler,))
|
||||||
log.debug("Relay: exporting links database to "+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)
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ def create(irc, source, args):
|
|||||||
channel = args[0].lower()
|
channel = args[0].lower()
|
||||||
except IndexError:
|
except IndexError:
|
||||||
utils.msg(irc, source, "Error: not enough arguments. Needs 1: channel.")
|
utils.msg(irc, source, "Error: not enough arguments. Needs 1: channel.")
|
||||||
return
|
return
|
||||||
if not utils.isChannel(channel):
|
if not utils.isChannel(channel):
|
||||||
utils.msg(irc, source, 'Error: invalid channel %r.' % channel)
|
utils.msg(irc, source, 'Error: invalid channel %r.' % channel)
|
||||||
return
|
return
|
||||||
@ -60,7 +60,7 @@ def destroy(irc, source, args):
|
|||||||
channel = args[0].lower()
|
channel = args[0].lower()
|
||||||
except IndexError:
|
except IndexError:
|
||||||
utils.msg(irc, source, "Error: not enough arguments. Needs 1: channel.")
|
utils.msg(irc, source, "Error: not enough arguments. Needs 1: channel.")
|
||||||
return
|
return
|
||||||
if not utils.isChannel(channel):
|
if not utils.isChannel(channel):
|
||||||
utils.msg(irc, source, 'Error: invalid channel %r.' % channel)
|
utils.msg(irc, source, 'Error: invalid channel %r.' % channel)
|
||||||
return
|
return
|
||||||
@ -77,12 +77,18 @@ def destroy(irc, source, args):
|
|||||||
utils.msg(irc, source, 'Error: no such relay %r exists.' % channel)
|
utils.msg(irc, source, 'Error: no such relay %r exists.' % channel)
|
||||||
|
|
||||||
def main(irc):
|
def main(irc):
|
||||||
global scheduler
|
|
||||||
scheduler = sched.scheduler()
|
|
||||||
loadDB()
|
loadDB()
|
||||||
scheduler.enter(60, 1, exportDB)
|
# HACK: we only want to schedule this once globally, because
|
||||||
thread = threading.Thread(target=scheduler.run)
|
# exportDB will otherwise be called by every network that loads this
|
||||||
thread.start()
|
# plugin.
|
||||||
|
if 'relaydb' not in utils.schedulers:
|
||||||
|
utils.schedulers['relaydb'] = scheduler = sched.scheduler()
|
||||||
|
scheduler.enter(30, 1, exportDB, argument=(scheduler,))
|
||||||
|
# Thread this because exportDB() queues itself as part of its
|
||||||
|
# execution, in order to get a repeating loop.
|
||||||
|
thread = threading.Thread(target=scheduler.run)
|
||||||
|
thread.start()
|
||||||
for chanpair in db:
|
for chanpair in db:
|
||||||
network, channel = chanpair
|
network, channel = chanpair
|
||||||
ircobj = utils.networkobjects[network]
|
ircobj = utils.networkobjects[network]
|
||||||
|
1
utils.py
1
utils.py
@ -9,6 +9,7 @@ global bot_commands, command_hooks
|
|||||||
bot_commands = {}
|
bot_commands = {}
|
||||||
command_hooks = defaultdict(list)
|
command_hooks = defaultdict(list)
|
||||||
networkobjects = {}
|
networkobjects = {}
|
||||||
|
schedulers = {}
|
||||||
|
|
||||||
class TS6UIDGenerator():
|
class TS6UIDGenerator():
|
||||||
"""TS6 UID Generator module, adapted from InspIRCd source
|
"""TS6 UID Generator module, adapted from InspIRCd source
|
||||||
|
Loading…
x
Reference in New Issue
Block a user