sheetsync: Review feedback

* Expand on some comments
* Fix conflicting port number
* Write help text for all args
pull/54/head
Mike Lang 6 years ago
parent 9762f308a0
commit 11fc67f071

@ -100,7 +100,8 @@ class SheetSync(object):
for worksheet in self.worksheets: for worksheet in self.worksheets:
rows = self.sheets.get_rows(self.sheet_id, worksheet) rows = self.sheets.get_rows(self.sheet_id, worksheet)
for row_index, row in enumerate(rows): for row_index, row in enumerate(rows):
# Skip first row. Need to do it inside the loop and not eg. use rows[1:], # Skip first row (ie. the column titles).
# Need to do it inside the loop and not eg. use rows[1:],
# because then row_index won't be correct. # because then row_index won't be correct.
if row_index == 0: if row_index == 0:
continue continue
@ -219,22 +220,37 @@ class SheetSync(object):
) )
@argh.arg('worksheet-names', nargs='+', help="The names of the individual worksheets within the sheet to operate on.") @argh.arg('dbconnect', help=
def main(dbconnect, sheets_creds_file, edit_url, bustime_start, sheet_id, worksheet_names, metrics_port=8004, backdoor_port=0, allocate_ids=False): "dbconnect should be a postgres connection string, which is either a space-separated "
"""dbconnect should be a postgres connection string, which is either a space-separated "list of key=value pairs, or a URI like:\n"
list of key=value pairs, or a URI like: "\tpostgresql://USER:PASSWORD@HOST/DBNAME?KEY=VALUE"
postgresql://USER:PASSWORD@HOST/DBNAME?KEY=VALUE )
@argh.arg('sheets-cred-file', help=
sheets_creds_file should be a json file containing keys 'client_id', 'client_secret' and 'refresh_token'. "sheets_creds_file should be a json file containing keys "
"'client_id', 'client_secret' and 'refresh_token'."
edit_url should be a format string for edit links, with {} as a placeholder for id. )
eg. "https://myeditor.example.com/edit/{}" will produce edit urls like @argh.arg('edit-url', help=
"https://myeditor.example.com/edit/da6cf4df-4871-4a9a-a660-0b1e1a6a9c10". 'edit_url should be a format string for edit links, with {} as a placeholder for id. '
'eg. "https://myeditor.example.com/edit/{}" will produce edit urls like '
bustime_start is the timestamp which is bustime 00:00. '"https://myeditor.example.com/edit/da6cf4df-4871-4a9a-a660-0b1e1a6a9c10".'
)
@argh.arg('bustime_start', type=common.dateutil.parse, help=
"bustime_start is the timestamp which is bustime 00:00."
)
@argh.arg('worksheet-names', nargs='+', help=
"The names of the individual worksheets within the sheet to operate on."
)
@argh.arg('--allocate-ids', help=
"--allocate-ids means that it will give rows without ids an id. "
"Only one sheet sync should have --allocate-ids on for a given sheet at once!"
)
def main(dbconnect, sheets_creds_file, edit_url, bustime_start, sheet_id, worksheet_names, metrics_port=8005, backdoor_port=0, allocate_ids=False):
"""
Sheet sync constantly scans a Google Sheets sheet and a database, copying inputs from the sheet
to the DB and outputs from the DB to the sheet.
--allocate-ids means that it will give rows without ids an id. With the exception of id allocation, all operations are idempotent and multiple sheet syncs
Only one sheet sync should have --allocate-ids on for a given sheet at once! may be run for redundancy.
""" """
common.PromLogCountsHandler.install() common.PromLogCountsHandler.install()
common.install_stacksampler() common.install_stacksampler()
@ -248,8 +264,6 @@ def main(dbconnect, sheets_creds_file, edit_url, bustime_start, sheet_id, worksh
stop = gevent.event.Event() stop = gevent.event.Event()
gevent.signal(signal.SIGTERM, stop.set) # shut down on sigterm gevent.signal(signal.SIGTERM, stop.set) # shut down on sigterm
bustime_start = common.dateutil.parse(bustime_start)
logging.info("Starting up") logging.info("Starting up")
dbmanager = DBManager(dsn=dbconnect) dbmanager = DBManager(dsn=dbconnect)

Loading…
Cancel
Save