summaryrefslogtreecommitdiff
path: root/alot/db/__init__.py
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2012-02-28 22:25:09 +0000
committerPatrick Totzke <patricktotzke@gmail.com>2012-05-17 15:38:58 +0100
commitb7541e8159f800a9e376c6af99591bc00c69bd12 (patch)
tree482f4a75c1029a96a14f5deb19c9364214086067 /alot/db/__init__.py
parentae175e909c35e6a598759c2b921028684f2e2837 (diff)
use new db's for writequeue entries in flush
This moves the creation / destruction of the notmuch.Database object used to change the index to the code for a single writequeue entry: Instead of using one db for all entries, we let each one have its own. This *should* allow the "afterwards" callback allow to retrieve data from an updated index, that already reflects the changes just made. issue #317
Diffstat (limited to 'alot/db/__init__.py')
-rw-r--r--alot/db/__init__.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/alot/db/__init__.py b/alot/db/__init__.py
index c6a83064..92b73258 100644
--- a/alot/db/__init__.py
+++ b/alot/db/__init__.py
@@ -69,13 +69,6 @@ class DBManager(object):
if self.ro:
raise errors.DatabaseROError()
if self.writequeue:
- # aquire a writeable db handler
- try:
- mode = Database.MODE.READ_WRITE
- db = Database(path=self.path, mode=mode)
- except NotmuchError:
- raise errors.DatabaseLockedError()
-
# read notmuch's config regarding imap flag synchronization
sync = settings.get_notmuch_setting('maildir', 'synchronize_flags')
@@ -90,6 +83,13 @@ class DBManager(object):
# the first two coordinants are cnmdname and post-callback
cmd, afterwards = current_item[:2]
+ # aquire a writeable db handler
+ try:
+ mode = Database.MODE.READ_WRITE
+ db = Database(path=self.path, mode=mode)
+ except NotmuchError:
+ raise DatabaseLockedError()
+
# make this a transaction
db.begin_atomic()
@@ -131,14 +131,22 @@ class DBManager(object):
if db.end_atomic() != notmuch.STATUS.SUCCESS:
raise errors.DatabaseError('end_atomic failed')
+ # close db
+ db.close()
+
# call post-callback
if callable(afterwards):
afterwards()
# re-insert item to the queue upon Xapian/NotmuchErrors
except (XapianError, NotmuchError) as e:
+ logging.exception(e)
+ self.writequeue.appendleft(current_item)
+ raise DatabaseError(unicode(e))
+ except DatabaseLockedError as e:
+ logging.exception(e)
self.writequeue.appendleft(current_item)
- raise errors.DatabaseError(unicode(e))
+ raise e
def kill_search_processes(self):
"""