Add Consumer.setup() method for datasync
				
					
				
			This commit is contained in:
		
							parent
							
								
									01357e7164
								
							
						
					
					
						commit
						2cfa543e05
					
				
					 2 changed files with 9 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -40,6 +40,11 @@ class DataSyncConsumer(object):
 | 
			
		|||
        self.key = key
 | 
			
		||||
        self.dbkey = dbkey
 | 
			
		||||
 | 
			
		||||
    def setup(self):
 | 
			
		||||
        """
 | 
			
		||||
        This method is called when the consumer thread is first started.
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
    def process_changes(self, session, changes):
 | 
			
		||||
        """
 | 
			
		||||
        Process (consume) a set of changes.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -179,6 +179,10 @@ def consume_changes(profile, consumers):
 | 
			
		|||
    """
 | 
			
		||||
    from rattail.db import Session, model
 | 
			
		||||
 | 
			
		||||
    # Let consumers do any setup they need.
 | 
			
		||||
    for consumer in consumers:
 | 
			
		||||
        consumer.setup()
 | 
			
		||||
 | 
			
		||||
    def process(session, consumer, changes):
 | 
			
		||||
        try:
 | 
			
		||||
            consumer.process_changes(session, changes)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue