From 4e2dfce449ac1ce7e45dddb241ceea9d899df5f8 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 21 Sep 2014 14:36:07 -0700 Subject: [PATCH] nmhive.py: Commit tag changes to nmbug There's a bit of a race here: we need to close the database before committing so that the change has been flushed to disk for nmbug to pick up, but that means we're not committing while protected by the read/write lock. Ideally, we could flush the database to disk, run the nmbug commit, and then close the database to release the lock. Unfortunately there is no "commit changes to the datatabase without closing" command exposed by notmuch, but maybe I can talk folks into adding one ;). On the other hand, the race is against parallel request that aquires the lock after we release it *and* gets their commit in before ours, which seems unlikely. Still, it would be better if we had a known-safe option here. --- nmhive.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nmhive.py b/nmhive.py index 6f9f346..06c2cd0 100755 --- a/nmhive.py +++ b/nmhive.py @@ -8,6 +8,7 @@ import urllib.request import flask import flask_cors +import nmbug import notmuch @@ -43,6 +44,7 @@ def _message_tags(message): @app.route('/mid/', methods=['GET', 'POST']) def message_id_tags(message_id): if flask.request.method == 'POST': + changes = flask.request.get_json() database = notmuch.Database( path=NOTMUCH_PATH, mode=notmuch.Database.MODE.READ_WRITE) @@ -52,7 +54,7 @@ def message_id_tags(message_id): return flask.Response(status=404) database.begin_atomic() message.freeze() - for change in flask.request.get_json(): + for change in changes: if change.startswith('+'): message.add_tag(TAG_PREFIX + change[1:]) elif change.startswith('-'): @@ -64,6 +66,8 @@ def message_id_tags(message_id): tags = _message_tags(message=message) finally: database.close() + nmbug.commit(message='nmhive: {} {}'.format( + message_id, ' '.join(changes))) elif flask.request.method == 'GET': database = notmuch.Database(path=NOTMUCH_PATH) try: -- 2.26.2