Browse Source

Configurable flush period

master
JustAnotherArchivist 3 years ago
parent
commit
53d276064a
2 changed files with 8 additions and 3 deletions
  1. +2
    -0
      config.example.toml
  2. +6
    -3
      irclog.py

+ 2
- 0
config.example.toml View File

@@ -7,6 +7,8 @@
[storage]
# Must point to an existing directory that is writable by the user running irclog. Relative paths are evaluated relative to the config file.
#path = '.'
# Time between flushing file contents in seconds. This determines how quickly new messages appear on the web interface.
#flushTime = 60

[irc]
#host = 'irc.hackint.org'


+ 6
- 3
irclog.py View File

@@ -90,7 +90,7 @@ class Config(dict):
except (ValueError, AssertionError) as e:
raise InvalidConfig('Invalid log format: parsing failed') from e
if 'storage' in obj:
if any(x != 'path' for x in obj['storage']):
if any(x not in ('path', 'flushTime') for x in obj['storage']):
raise InvalidConfig('Unknown key found in storage section')
if 'path' in obj['storage']:
obj['storage']['path'] = os.path.abspath(os.path.join(os.path.dirname(self._filename), obj['storage']['path']))
@@ -100,6 +100,9 @@ class Config(dict):
f.close()
except (OSError, IOError) as e:
raise InvalidConfig('Invalid storage path: not writable') from e
if 'flushTime' in obj['storage']:
if not isinstance(obj['storage']['flushTime'], (int, float)) or obj['storage']['flushTime'] <= 0:
raise InvalidConfig('Invalid storage flushTime: must be a positive int or float')
if 'irc' in obj:
if any(x not in ('host', 'port', 'ssl', 'nick', 'real', 'certfile', 'certkeyfile') for x in obj['irc']):
raise InvalidConfig('Unknown key found in irc section')
@@ -216,7 +219,7 @@ class Config(dict):
raise InvalidConfig(f'Invalid channel {key!r} extrasearchchannels: refers to auth-required channel whose auth differs from this channel\'s')

# Default values
finalObj = {'logging': {'level': 'INFO', 'format': '{asctime} {levelname} {name} {message}'}, 'storage': {'path': os.path.abspath(os.path.dirname(self._filename))}, 'irc': {'host': 'irc.hackint.org', 'port': 6697, 'ssl': 'yes', 'nick': 'irclogbot', 'real': 'I am an irclog bot.', 'certfile': None, 'certkeyfile': None}, 'web': {'host': '127.0.0.1', 'port': 8080}, 'channels': {}}
finalObj = {'logging': {'level': 'INFO', 'format': '{asctime} {levelname} {name} {message}'}, 'storage': {'path': os.path.abspath(os.path.dirname(self._filename)), 'flushTime': 60}, 'irc': {'host': 'irc.hackint.org', 'port': 6697, 'ssl': 'yes', 'nick': 'irclogbot', 'real': 'I am an irclog bot.', 'certfile': None, 'certkeyfile': None}, 'web': {'host': '127.0.0.1', 'port': 8080}, 'channels': {}}
# Default values for channels are already set above.

# Merge in what was read from the config file and set keys on self
@@ -735,7 +738,7 @@ class Storage:

async def flush_files(self, flushExitEvent):
while True:
await asyncio.wait({flushExitEvent.wait()}, timeout = 60)
await asyncio.wait({flushExitEvent.wait()}, timeout = self.config['storage']['flushTime'])
self.logger.debug('Flushing files')
for _, f in self.files.values():
f.flush()


Loading…
Cancel
Save