From 00766041f351cb8a6bb3eb9c77c1f9e7e8488768 Mon Sep 17 00:00:00 2001 From: James Lu Date: Thu, 7 Jul 2016 22:16:21 -0700 Subject: [PATCH] plugins: make DB save delay configurable --- example-conf.yml | 5 +++++ plugins/automode.py | 7 ++++--- plugins/relay.py | 7 +++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/example-conf.yml b/example-conf.yml index 0022263..8a0e213 100644 --- a/example-conf.yml +++ b/example-conf.yml @@ -36,6 +36,11 @@ bot: # False. protect_services: false + # Determines how long plugins should wait (in seconds) before flushing their + # databases to disk. Defaults to 300 seconds. Changes here require a reload + # of all database-enabled plugins to take effect. + save_delay: 300 + login: # PyLink administrative login - Change this, or the service will not start! user: admin diff --git a/plugins/automode.py b/plugins/automode.py index a88ba36..c71ea2a 100644 --- a/plugins/automode.py +++ b/plugins/automode.py @@ -6,7 +6,7 @@ import collections import threading import json -from pylinkirc import utils +from pylinkirc import utils, conf from pylinkirc.log import log mydesc = ("The \x02Automode\x02 plugin provides simple channel ACL management by giving prefix modes " @@ -21,6 +21,8 @@ dbname = utils.getDatabaseName('automode') db = collections.defaultdict(dict) exportdb_timer = None +save_delay = conf.conf['bot'].get('save_delay', 300) + def loadDB(): """Loads the Automode database, silently creating a new one if this fails.""" global db @@ -50,8 +52,7 @@ def scheduleExport(starting=False): # thing after start (i.e. DB has just been loaded). exportDB() - # TODO: possibly make delay between exports configurable - exportdb_timer = threading.Timer(30, scheduleExport) + exportdb_timer = threading.Timer(save_delay, scheduleExport) exportdb_timer.name = 'Automode exportDB Loop' exportdb_timer.start() diff --git a/plugins/relay.py b/plugins/relay.py index 0568b30..a9204b6 100644 --- a/plugins/relay.py +++ b/plugins/relay.py @@ -5,7 +5,7 @@ import threading import string from collections import defaultdict -from pylinkirc import utils, world +from pylinkirc import utils, world, conf from pylinkirc.log import log ### GLOBAL (statekeeping) VARIABLES @@ -15,7 +15,7 @@ spawnlocks = defaultdict(threading.RLock) spawnlocks_servers = defaultdict(threading.RLock) exportdb_timer = None - +save_delay = conf.conf['bot'].get('save_delay', 300) db = {} dbname = utils.getDatabaseName('pylinkrelay') @@ -193,8 +193,7 @@ def scheduleExport(starting=False): # thing after start (i.e. DB has just been loaded). exportDB() - # TODO: possibly make delay between exports configurable - exportdb_timer = threading.Timer(30, scheduleExport) + exportdb_timer = threading.Timer(save_delay, scheduleExport) exportdb_timer.name = 'PyLink Relay exportDB Loop' exportdb_timer.start()