Repository navigation
refactor(store): the Store gets its storage settings from its caller - #250
Merged
Merged
Conversation
store/files.py no longer reads the settings loader through sys.modules. The Store takes a function for its [storage] section (store.use_settings); the loader passes its own when it is imported, and the Store calls it on every read, so a changed environment or a reload still applies to the next write. A process without the loader, or a failing function, uses the defaults. tests/test_layers.py now also checks that no Store module looks into sys.modules; the doctor goldens list the four light Store modules that importing the configuration now loads.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the open item of
03-implementation-plan.mdsection 20: "sofascore_scraper/store/files.pygets its durability from the caller".What changes
store/files.pyno longer looks upsofascore_scraper.config.loaderinsys.modules. It has a new public function,sofascore_scraper.store.use_settings(source).sourceis a function that returns the[storage]section (data_dir,durability,open_reconcile_seconds). The Store calls it on every read. If no function was given, or the function raises, the Store uses the defaults: no fsync,data, 60 s.config/loader.pypasses_store_settings(the active settings'storage) when the loader is imported. The Store still imports nothing from the configuration.Why a settings function, and not a value at
open_storeStoreobject.files.write_bytes,publish_diranddurability_fullare module functions. Other Store modules call them in about 23 places, and those calls have noStoreat hand.active()call. That affects the env-var case anddefault_data_dir. Asking the loader for the section on every read is exactly today's behaviour.Live changes
They still apply, as before. A changed
SOFASCORE_STORAGE__*variable or areload()ofsofascore.toml/overrides.jsonapplies to the next write. The Settings page does not editstorage.durabilityand still marks it as needing a restart. No change users can see, so there is no CHANGELOG entry.Tests
tests/test_store_files.py: the durability tests now use a fake settings function and no longer need the loader. They cover full/normal, thedurable=override, the function being called on every write, the other two settings, and the defaults when no function was given or it raises.tests/test_config_loader.py: the file value and a reload reachfiles. An env change is seen at once.FULLandfullare normalised, andSTORE_DURABILITYis not read. A separate process checks that importing the configuration gives the Store the settings.tests/test_layers.py: no Store module mentionssys.modules.tests/fixtures/store_api/use_settings.txt.ssc doctorCLI goldens now listsofascore_scraper.store,.errors,.filesand.layout. Importing the configuration loads them now; none of them uses SQLite or the network.ruff is clean. Full suite: 9883 passed, 45 skipped, also with
STORE_SHADOW_CHECK=1.Docs
01-storage.md4.4 and item 150,02-services.md(4.3 and the risks list),README.md(the open list) and03section 20 ("Done").