Add Consumer.setup() method for datasync

This commit is contained in:
Lance Edgar 2016-04-21 13:33:22 -05:00
parent 01357e7164
commit 2cfa543e05
2 changed files with 9 additions and 0 deletions

View file

@ -40,6 +40,11 @@ class DataSyncConsumer(object):
self.key = key self.key = key
self.dbkey = dbkey self.dbkey = dbkey
def setup(self):
"""
This method is called when the consumer thread is first started.
"""
def process_changes(self, session, changes): def process_changes(self, session, changes):
""" """
Process (consume) a set of changes. Process (consume) a set of changes.

View file

@ -179,6 +179,10 @@ def consume_changes(profile, consumers):
""" """
from rattail.db import Session, model from rattail.db import Session, model
# Let consumers do any setup they need.
for consumer in consumers:
consumer.setup()
def process(session, consumer, changes): def process(session, consumer, changes):
try: try:
consumer.process_changes(session, changes) consumer.process_changes(session, changes)