Add transaction logic for rattail->rattail datasync
per newer conventions
This commit is contained in:
parent
24a0587eab
commit
9c47822eaf
|
@ -426,35 +426,32 @@ class FromRattailToRattailExportConsumer(FromRattailToRattailBase):
|
||||||
def make_target_session(self):
|
def make_target_session(self):
|
||||||
return self.app.make_session(bind=self.target_engine)
|
return self.app.make_session(bind=self.target_engine)
|
||||||
|
|
||||||
def process_changes(self, session, changes):
|
def begin_transaction(self):
|
||||||
local_session = self.app.make_session()
|
self.local_session = self.app.make_session()
|
||||||
target_session = self.make_target_session()
|
self.target_session = self.make_target_session()
|
||||||
|
|
||||||
try:
|
def rollback_transaction(self):
|
||||||
|
self.target_session.rollback()
|
||||||
|
self.target_session.close()
|
||||||
|
del self.target_session
|
||||||
|
|
||||||
|
self.local_session.rollback()
|
||||||
|
self.local_session.close()
|
||||||
|
del self.local_session
|
||||||
|
|
||||||
|
def commit_transaction(self):
|
||||||
|
# TODO: should we ever commit local?
|
||||||
|
#self.local_session.commit()
|
||||||
|
self.target_session.commit()
|
||||||
|
|
||||||
|
def pre_process_changes(self, session, changes):
|
||||||
if self.runas_username:
|
if self.runas_username:
|
||||||
target_session.set_continuum_user(self.runas_username)
|
self.target_session.set_continuum_user(self.runas_username)
|
||||||
|
|
||||||
# update all importers with current sessions
|
# update all importers with current sessions
|
||||||
for importer in six.itervalues(self.importers):
|
for importer in six.itervalues(self.importers):
|
||||||
importer.host_session = local_session
|
importer.host_session = self.local_session
|
||||||
importer.session = target_session
|
importer.session = self.target_session
|
||||||
|
|
||||||
# delegate processing to importer(s)
|
|
||||||
for change in changes:
|
|
||||||
self.invoke_importer(session, change)
|
|
||||||
|
|
||||||
# TODO: should we ever commit local?
|
|
||||||
#local_session.commit()
|
|
||||||
target_session.commit()
|
|
||||||
|
|
||||||
except:
|
|
||||||
log.exception("failed to process changes")
|
|
||||||
local_session.rollback()
|
|
||||||
target_session.rollback()
|
|
||||||
|
|
||||||
finally:
|
|
||||||
local_session.close()
|
|
||||||
target_session.close()
|
|
||||||
|
|
||||||
|
|
||||||
class FromRattailToRattailImportConsumer(FromRattailToRattailBase):
|
class FromRattailToRattailImportConsumer(FromRattailToRattailBase):
|
||||||
|
|
Loading…
Reference in a new issue