Skip to content

Commit fd39a27

Browse files
committed
adding annotation
1 parent aff894e commit fd39a27

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

main.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,15 @@ def cleanup(*args):
4646

4747
table_structure = {}
4848

49-
DUMP_CMD = 'mysqldump -h {host} -P {port} -u {user} --password={password} {db} {table} --default-character-set=utf8' \
50-
' -X'\
49+
DUMP_CMD = 'mysqldump -h {host} -P {port} -u {user} --password={password} {db} {table} ' \
50+
'--default-character-set=utf8 -X'\
5151
.format(**config['mysql'])
5252
BINLOG_CFG = {key: config['mysql'][key] for key in ['host', 'port', 'user', 'password', 'db']}
5353
BULK_SIZE = config.get('elastic').get('bulk_size')
5454

5555
log_file = None
5656
log_pos = None
5757

58-
5958
record_path = config['binlog_sync']['record_file']
6059
if os.path.isfile(record_path):
6160
with open(record_path, 'r') as f:
@@ -102,6 +101,9 @@ def bulker(bulk_size=BULK_SIZE):
102101

103102

104103
def updater(data):
104+
"""
105+
encapsulation of bulker
106+
"""
105107
u = bulker()
106108
u.send(None) # push the generator to first yield
107109
for item in data:
@@ -110,6 +112,9 @@ def updater(data):
110112

111113

112114
def json_serializer(obj):
115+
"""
116+
format the object which json not supported
117+
"""
113118
if isinstance(obj, datetime):
114119
return obj.isoformat()
115120
raise TypeError('Type not serializable')
@@ -163,6 +168,9 @@ def mapper(data):
163168

164169

165170
def formatter(data):
171+
"""
172+
format every field from xml, according to parsed table structure
173+
"""
166174
for item in data:
167175
for field, serializer in table_structure.items():
168176
if item['doc'][field]:
@@ -172,6 +180,9 @@ def formatter(data):
172180

173181

174182
def binlog_loader():
183+
"""
184+
read row from binlog
185+
"""
175186
global log_file
176187
global log_pos
177188
if log_file and log_pos:
@@ -212,6 +223,9 @@ def binlog_loader():
212223

213224

214225
def parse_table_structure(data):
226+
"""
227+
parse the table structure
228+
"""
215229
global table_structure
216230
for item in data.iter():
217231
if item.tag == 'field':
@@ -222,7 +236,7 @@ def parse_table_structure(data):
222236
elif 'float' in type:
223237
serializer = float
224238
elif 'datetime' in type:
225-
if '(6)' in type:
239+
if '(' in type:
226240
serializer = lambda x: datetime.strptime(x, '%Y-%m-%d %H:%M:%S.%f')
227241
else:
228242
serializer = lambda x: datetime.strptime(x, '%Y-%m-%d %H:%M:%S')
@@ -301,6 +315,9 @@ def xml_file_loader(filename):
301315

302316

303317
def send_email(title, content):
318+
"""
319+
send notification email
320+
"""
304321
if not config.get('email'):
305322
return
306323

0 commit comments

Comments
 (0)