Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync changes in the db after each task execution. #228

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions doit/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def dump(self):
finally:
db_file.close()

sync = dump

def set(self, task_id, dependency, value):
"""Store value in the DB."""
if task_id not in self._db:
Expand Down Expand Up @@ -162,6 +164,11 @@ def dump(self):
self._dbm[task_id] = json.dumps(self._db[task_id])
self._dbm.close()

def sync(self):
for task_id in self.dirty:
self._dbm[task_id] = json.dumps(self._db[task_id])
self._dbm.sync()
self.dirty = set()

def set(self, task_id, dependency, value):
"""Store value in the DB."""
Expand Down Expand Up @@ -319,6 +326,14 @@ def dump(self):
self._conn.close()
self._dirty = set()

def sync(self):
"""save/close sqlite3 DB file"""
for task_id in self._dirty:
self._conn.execute('insert or replace into doit values (?,?)',
(task_id, json.dumps(self._cache[task_id])))
self._conn.commit()
self._dirty = set()

def remove(self, task_id):
"""remove saved dependencies from DB for taskId"""
if task_id in self._cache:
Expand Down Expand Up @@ -479,6 +494,7 @@ def __init__(self, db_class, backend_name, checker_cls=MD5Checker):
self.remove_all = self.backend.remove_all
self._in = self.backend.in_
self.name = self.backend.name
self.sync = self.backend.sync

def close(self):
"""Write DB in file"""
Expand Down Expand Up @@ -515,6 +531,7 @@ def save_success(self, task, result_hash=None):

# save list of file_deps
self._set(task.name, 'deps:', tuple(task.file_dep))
self.sync()

def get_values(self, task_name):
"""get all saved values from a task
Expand Down