mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-22 07:56:18 -05:00
Keep playlists.yaml in shared memory so the perpetual process can save it (#881)
playlists_config was the only config not attached to a shared_ctx dict. Switches save configs in the perpetual process, which never imports the files, so its playlists_config kept the default version 0. While the database had no version row for playlists.yaml, the dump wrote version 1 and `save` refused to overwrite the newer file; the refused save never recorded the row, so every later save was refused too, and new playlists never reached the config. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ae97727b98
commit
eb82489426
2 changed files with 26 additions and 0 deletions
|
|
@ -34,6 +34,7 @@ def attach_shared_contexts(app: Sanic):
|
|||
app.shared_ctx.videos_downloader_config = manager.dict()
|
||||
app.shared_ctx.domains_config = manager.dict()
|
||||
app.shared_ctx.repos_config = manager.dict()
|
||||
app.shared_ctx.playlists_config = manager.dict()
|
||||
app.shared_ctx.archive_downloader_config = manager.dict()
|
||||
app.shared_ctx.download_cache_config = manager.dict()
|
||||
app.shared_ctx.map_pins_config = manager.dict()
|
||||
|
|
@ -130,6 +131,7 @@ def reset_shared_contexts(app: Sanic):
|
|||
app.shared_ctx.videos_downloader_config.clear()
|
||||
app.shared_ctx.domains_config.clear()
|
||||
app.shared_ctx.repos_config.clear()
|
||||
app.shared_ctx.playlists_config.clear()
|
||||
app.shared_ctx.archive_downloader_config.clear()
|
||||
app.shared_ctx.download_cache_config.clear()
|
||||
# Shared dicts.
|
||||
|
|
@ -304,6 +306,12 @@ def initialize_configs_contexts(app: Sanic):
|
|||
except Exception as e:
|
||||
logger.error(f'Failed to initialize in-memory repos config: {e}')
|
||||
|
||||
try:
|
||||
from wrolpi.collections.config import playlists_config
|
||||
playlists_config.initialize(app.shared_ctx.playlists_config)
|
||||
except Exception as e:
|
||||
logger.error(f'Failed to initialize in-memory playlists config: {e}')
|
||||
|
||||
try:
|
||||
from modules.archive.lib import ARCHIVE_DOWNLOADER_CONFIG
|
||||
ARCHIVE_DOWNLOADER_CONFIG.initialize(app.shared_ctx.archive_downloader_config)
|
||||
|
|
|
|||
|
|
@ -38,3 +38,21 @@ def test_domains_config_in_shared_context():
|
|||
for config_name in expected_configs:
|
||||
assert hasattr(test_app.shared_ctx, config_name), \
|
||||
f"{config_name} not found in shared_ctx"
|
||||
|
||||
|
||||
def test_all_configs_in_shared_context():
|
||||
"""Every config keeps its in-memory data in shared memory. Switches save configs in the perpetual process, which
|
||||
does not import the files; a config with process-local data would save a stale version there."""
|
||||
from multiprocessing.managers import DictProxy
|
||||
|
||||
from sanic import Sanic
|
||||
from wrolpi.common import get_all_configs
|
||||
from wrolpi.contexts import attach_shared_contexts, initialize_configs_contexts
|
||||
|
||||
test_app = Sanic(f"test_context_{id(test_all_configs_in_shared_context)}")
|
||||
attach_shared_contexts(test_app)
|
||||
initialize_configs_contexts(test_app)
|
||||
|
||||
not_shared = sorted(name for name, config in get_all_configs().items()
|
||||
if not isinstance(getattr(config, '_config', None), DictProxy))
|
||||
assert not_shared == [], 'Add these configs to attach_shared_contexts() and initialize_configs_contexts()'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue