1
0
mirror of synced 2024-11-27 23:50:47 +01:00

Auto-prune event log entries after some time.

This commit is contained in:
Jennifer Taylor 2020-05-08 18:22:31 +00:00
parent 645e7dc55a
commit 368efe2c63
5 changed files with 21 additions and 2 deletions

View File

@ -8,4 +8,3 @@ Things that I have not gotten around to doing.
- Make the frontend work better on mobile. It works well enough, but it could be a much better experience.
- Support for DanEvo. I meant to do this but my DanEvo ended up in storage before I could tackle it, so the only thing that exists at the moment is a rudimentary music DB parser.
- Figure out phase/unlock/etc bits for some older IIDX and Pop'n Music versions and hook them up to the Arcade panel to allow switching events.
- Auto-prune events in the event log after some configured date. Currently it grows indefinitely which is fine for small hobby setups but could be a problem with lots of events.

View File

@ -298,3 +298,11 @@ class NetworkData(BaseData):
),
)
return events
def delete_events(self, oldest_event_ts: int) -> None:
"""
Given a timestamp of the oldset event we should keep around, delete
all events older than this timestamp.
"""
sql = "DELETE FROM audit WHERE timestamp < :ts"
self.execute(sql, {'ts': oldest_event_ts})

View File

@ -56,6 +56,8 @@
<dd>{{ 'yes' if config['paseli']['enabled'] else 'no' }} (can be overridden by arcade settings)</dd>
<dt>Infinite PASELI Enabled</dt>
<dd>{{ 'yes' if config['paseli']['infinite'] else 'no' }} (can be overridden by arcade settings)</dd>
<dt>Event Log Preservation Duration</dt>
<dd>{{ (config['event_log_duration']|string + ' seconds') if config['event_log_duration'] else 'infinite' }}</dd>
</dl>
</div>
{% endblock %}

View File

@ -18,7 +18,7 @@ from bemani.frontend.ddr import DDRCache
from bemani.frontend.sdvx import SoundVoltexCache
from bemani.frontend.reflec import ReflecBeatCache
from bemani.frontend.museca import MusecaCache
from bemani.common import GameConstants
from bemani.common import GameConstants, Time
from bemani.data import Data
@ -61,6 +61,13 @@ def run_scheduled_work(config: Dict[str, Any]) -> None:
for cache in enabled_caches:
cache.preload(data, config) # type: ignore
# Now, possibly delete old log entries
keep_duration = config.get('event_log_duration', 0)
if keep_duration > 0:
# Calculate timestamp of events we should delete
oldest_event = Time.now() - keep_duration
data.local.network.delete_events(oldest_event)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="A scheduler for work that needs to be done periodically.")

View File

@ -57,3 +57,6 @@ name: 'e-AMUSEMENT Network'
email: 'nobody@nowhere.com'
# Cache DIR, should point somewhere other than /tmp for production instances
cache_dir: '/tmp'
# Number of seconds to preserve event logs before deleting them.
# Set to zero to disable deleting logs.
event_log_duration: 2592000