Last active
January 4, 2016 19:09
-
-
Save nl5887/8665492 to your computer and use it in GitHub Desktop.
Joins ElasticSearch commit into pyramid transaction manager
This file contains 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
import transaction | |
class ElasticSearchIndexManager(object): | |
def __init__(self, callable, args, kwargs): | |
self.callable = callable | |
self.args = args | |
self.kwargs = kwargs | |
# Use the default thread transaction manager. | |
self.transaction_manager = transaction.manager | |
def commit(self, transaction): | |
pass | |
def abort(self, transaction): | |
pass | |
def sortKey(self): | |
return id(self) | |
# No subtransaction support. | |
def abort_sub(self, transaction): | |
pass # pragma NO COVERAGE | |
commit_sub = abort_sub | |
def beforeCompletion(self, transaction): | |
pass # pragma NO COVERAGE | |
afterCompletion = beforeCompletion | |
def tpc_begin(self, transaction, subtransaction=False): | |
assert not subtransaction | |
def tpc_vote(self, transaction): | |
pass | |
def tpc_finish(self, transaction): | |
self.callable(*self.args, **self.kwargs) | |
tpc_abort = abort | |
class TransactionElasticSearch(pyelasticsearch.ElasticSearch): | |
def index(self, *a, **kw): | |
# only index on commit | |
index_ = super(TransactionElasticSearch, self).index | |
transaction.get().join(ElasticSearchIndexManager(index_, a, kw)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment