-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwait_for_table
executable file
·66 lines (58 loc) · 3.57 KB
/
wait_for_table
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/python
import legoo
import sys
from optparse import OptionParser
def main():
usage = """
check if table exists, and updated after [update_after]
if not, retry based on [sleep_interval], [num_retry] and/or [stop_at]
NOTE:
1. need access to INFORMATION_SCHEMA.TABLES to retrieve update_time
2. option [stop_at] i.e. [2013-10-08 15:30], together with [update_after]
i.e. [2013-10-09 14:25], define the table wait window
3. option [ETL_TABLE] and [ETL_JOB] are trulia specific which retrive table last update
from proprietary [AUDIT_JOB] database
======================================================
./wait_for_table --mysql_table='tmp_dim_property' --update_after='2013-10-10 16:07' --sleep_interval=10 --num_retry=20 --stop_at='2013-10-10 16:12' --debug='Y'
======================================================
"""
# create new parser object
parser = OptionParser(usage=usage)
# register mysql options
parser.add_option("--mysql_host", dest="mysql_host",
help="target mysql host. default: [bidbs]", default='bidbs')
parser.add_option("--mysql_db", dest="mysql_db",
help="target mysql database. default: [bi_staging]", default='bi_staging')
parser.add_option("--mysql_user", dest="mysql_user", help="mysql user")
parser.add_option("--mysql_password", dest="mysql_password", help="mysql password")
parser.add_option("--mysql_table", dest="mysql_table", help=" mysql table name")
parser.add_option("--update_after", dest="update_after",
help="mysql table modified after datetime [yyyy-mm-dd hh:mm] i.e. [2013-10-09 14:25]")
parser.add_option("--etl_table", dest="etl_table", help=" mysql table name. WARNING: TRULIA proprietary")
parser.add_option("--etl_job", dest="etl_job", help="job name. WARNING: TRULIA proprietary")
parser.add_option("-s", "--sleep_interval", dest="sleep_interval",
help="OPTIONAL: sleep for approximately S seconds between iterations. default: [60]", default=60)
parser.add_option("-n", "--num_retry", dest="num_retry", help="OPTIONAL: number of retry")
parser.add_option("-a", "--stop_at", dest="stop_at",
help="OPTIONAL: stop waiting at datetime [yyyy-mm-dd hh:mm]. i.e. [2013-10-08 15:30]")
parser.add_option("-q", "--quiet", "--silent", dest="quiet",
help="OPTIONAL: suppress messages to stdout. default: [N]", default='N')
parser.add_option("-d", "--debug", dest="debug", help="debug flag [Y|N], default: [N]", default='N')
# parse option and args
(options, args) = parser.parse_args()
legoo.wait_for_table(mysql_host = options.mysql_host, \
mysql_db = options.mysql_db, \
mysql_user = options.mysql_user, \
mysql_password = options.mysql_password, \
mysql_table = options.mysql_table, \
etl_table = options.etl_table, \
etl_job = options.etl_job, \
mysql_table_update_after = options.update_after, \
sleep_interval = options.sleep_interval, \
num_retry = options.num_retry, \
stop_at = options.stop_at, \
quiet = options.quiet, \
debug = options.debug
)
if __name__ == '__main__':
main()