mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-27 21:19:31 +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)
|
||||
db = {}
|
||||
|
||||
def exportDB():
|
||||
scheduler.enter(10, 1, exportDB)
|
||||
log.debug("Relay: exporting links database to "+dbname)
|
||||
def exportDB(scheduler):
|
||||
scheduler.enter(60, 1, exportDB, argument=(scheduler,))
|
||||
log.debug("Relay: exporting links database to %s", dbname)
|
||||
with open(dbname, 'wb') as f:
|
||||
pickle.dump(db, f, protocol=4)
|
||||
|
||||
@ -77,10 +77,16 @@ def destroy(irc, source, args):
|
||||
utils.msg(irc, source, 'Error: no such relay %r exists.' % channel)
|
||||
|
||||
def main(irc):
|
||||
global scheduler
|
||||
scheduler = sched.scheduler()
|
||||
|
||||
loadDB()
|
||||
scheduler.enter(60, 1, exportDB)
|
||||
# HACK: we only want to schedule this once globally, because
|
||||
# exportDB will otherwise be called by every network that loads this
|
||||
# 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:
|
||||
|
Loading…
Reference in New Issue
Block a user