Skip to content

Commit b435931

Browse files
author
xiongjianqiang
committed
Make sync start tiem configurable
1 parent 3a82b4a commit b435931

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

mongo_sync/config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@ blacklist: []
1111

1212
oplog_start_time: 2018-11-01T00:00:00
1313

14+
sync_start_time:
15+
1416
# minutes between oplog dumping
1517
oplog_dump_interval: 10
1618

1719
oplog_store_url: ''
1820

1921
oplog_store_db: 'oplog_store'
2022

23+
# days of oplog to keep
24+
keep_days: 2
25+
2126
logging:
2227
version: 1
2328
disable_existing_loggers: False

mongo_sync/oplog_manager.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ def _initialize_slice_range(self, start, interval):
6161

6262
LOG.info('Initial ts={}, interval={}'.format(self._start_ts, interval))
6363

64+
@property
65+
def is_running(self):
66+
return self._running
67+
6468
def remove_expiration(self):
6569
slice_names = self._oplog_store.list_names()
6670

@@ -133,7 +137,7 @@ def run_dumping(self):
133137
self._hungry = False
134138
self.slice_oplog()
135139

136-
LOG.info('Stopped.')
140+
LOG.warning('Oplog dumping stopped.')
137141

138142
def start(self):
139143
self._running = True

mongo_sync/oplog_reader.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,25 @@
2525

2626
class OplogReader(object):
2727

28-
def __init__(self, start):
28+
def __init__(self, start=None):
2929

3030
self._oplog_store = OplogStore()
3131

3232
self._running = False
33-
_dt = dateutil.parser.parse(start)
34-
self._last_ts = dt2ts(_dt)
33+
34+
start = start or conf['sync_start_time']
35+
if not isinstance(start, datetime.datetime):
36+
raise TypeError('Expect datetime.datetime, got {}'.format(
37+
type(start)))
38+
39+
self._last_ts = dt2ts(start)
3540

3641
self.docman = DocManager()
3742

43+
@property
44+
def is_running(self):
45+
return self._running
46+
3847
def load_oplog(self):
3948
oplog = self._oplog_store.load_oplog(self._last_ts)
4049
if oplog:

0 commit comments

Comments
 (0)