Changeset - 1e2491a5a9fa
[Not reviewed]
0 3 0
Lance Edgar (lance) - 11 years ago 2013-11-16 01:07:57
lance@edbob.org
More db sync fixes (tested on Windows).
3 files changed with 11 insertions and 9 deletions:
0 comments (0 inline, 0 general)
rattail/db/sync/__init__.py
Show inline comments
 
@@ -103,7 +103,7 @@ class Synchronizer(object):
 
                ', '.join(self.remote_engines.iterkeys())))
 
        while True:
 
            try:
 
                self.synchronize_changes()
 
                self.synchronize()
 
            except OperationalError, error:
 
                if error.connection_invalidated:
 
                    # Presumably a database server restart; give it a moment
 
@@ -303,8 +303,10 @@ def synchronize_changes(local_engine, remote_engines):
 

	
 
    factory = edbob.config.get('rattail.db', 'sync.synchronizer_class')
 
    if factory:
 
        log.debug("synchronize_changes: using custom synchronizer factory: {0}".format(repr(factory)))
 
        factory = edbob.load_spec(factory)
 
    else:
 
        log.debug("synchronize_changes: using default synchronizer factory")
 
        factory = Synchronizer
 

	
 
    synchronizer = factory(local_engine, remote_engines)
rattail/db/sync/win32.py
Show inline comments
 
@@ -31,8 +31,9 @@ import logging
 
import threading
 

	
 
import edbob
 
from edbob.win32 import Service
 
from edbob import db
 

	
 
from rattail.win32.service import Service
 
from rattail.db.sync import get_sync_engines, synchronize_changes
 

	
 

	
 
@@ -62,15 +63,14 @@ class DatabaseSynchronizerService(Service):
 

	
 
        edbob.init_modules(['rattail.db'])
 

	
 
        engines = get_sync_engines()
 
        if not engines:
 
        remote_engines = get_sync_engines()
 
        if not remote_engines:
 
            return False
 

	
 
        thread = threading.Thread(target=synchronize_changes,
 
                                  args=(engines,))
 
                                  args=(db.engine, remote_engines))
 
        thread.daemon = True
 
        thread.start()
 

	
 
        return True
 

	
 

	
tests/db/sync/test_init.py
Show inline comments
 
@@ -36,12 +36,12 @@ class SynchronizerTests(TestCase):
 

	
 
        synchronizer = sync.Synchronizer(self.local_engine, self.remote_engines)
 
        with patch.object(synchronizer, 'sleep') as sleep:
 
            with patch.object(synchronizer, 'synchronize_changes') as synchronize_changes:
 
            with patch.object(synchronizer, 'synchronize') as synchronize:
 

	
 
                synchronize_changes.side_effect = [1, 2, 3, FakeOperationalError(True),
 
                synchronize.side_effect = [1, 2, 3, FakeOperationalError(True),
 
                                                   5, 6, 7, FakeOperationalError(False)]
 
                self.assertRaises(FakeOperationalError, synchronizer.loop)
 
                self.assertEqual(synchronize_changes.call_count, 8)
 
                self.assertEqual(synchronize.call_count, 8)
 
                self.assertEqual(sleep.call_args_list, [
 
                        call(3), call(3), call(3), call(5), call(3),
 
                        call(3), call(3), call(3)])
0 comments (0 inline, 0 general)