[Core] Removed flusher, helpers now save on changes

After some considerations, while the flusher was an interesting experiment, it doesn't seem to be reliable enough. It's been removed in favor of the helpers autosaving on any change in a threadsafe way.
This commit is contained in:
Twentysix
2017-04-29 19:25:10 +02:00
parent bd341f1875
commit 9fc4e54ece
6 changed files with 48 additions and 137 deletions

View File

@@ -16,9 +16,8 @@ MINIFIED = {"sort_keys": True, "separators": (',', ':')}
class JsonIO:
"""Basic functions for atomic saving / loading of json files
This is inherited by the flusher and db helpers"""
"""Basic functions for atomic saving / loading of json files"""
_lock = asyncio.Lock()
def _save_json(self, path, data, settings=PRETTY):
log.debug("Saving file {}".format(path))
@@ -31,7 +30,8 @@ class JsonIO:
async def _threadsafe_save_json(self, path, data, settings=PRETTY):
loop = asyncio.get_event_loop()
func = functools.partial(self._save_json, path, data, settings)
await loop.run_in_executor(None, func)
with await self._lock:
await loop.run_in_executor(None, func)
def _load_json(self, path):
log.debug("Reading file {}".format(path))
@@ -43,4 +43,5 @@ class JsonIO:
loop = asyncio.get_event_loop()
func = functools.partial(self._load_json, path)
task = loop.run_in_executor(None, func)
return await asyncio.wait_for(task)
with await self._lock:
return await asyncio.wait_for(task)