sheetsync: Move edit url management into Sheets middleware

As streamlog doesn't require it.
pull/401/head
Mike Lang 1 year ago committed by Mike Lang
parent be111ccb2a
commit d064522d60

@ -69,11 +69,10 @@ class SheetSync(object):
# Time to wait after getting an error # Time to wait after getting an error
ERROR_RETRY_INTERVAL = 10 ERROR_RETRY_INTERVAL = 10
def __init__(self, middleware, stop, dbmanager, edit_url): def __init__(self, middleware, stop, dbmanager):
self.middleware = middleware self.middleware = middleware
self.stop = stop self.stop = stop
self.dbmanager = dbmanager self.dbmanager = dbmanager
self.edit_url = edit_url
# List of input columns # List of input columns
self.input_columns = [ self.input_columns = [
'event_start', 'event_start',
@ -223,19 +222,6 @@ class SheetSync(object):
rows_changed.labels('output', worksheet).inc() rows_changed.labels('output', worksheet).inc()
self.middleware.mark_modified(worksheet) self.middleware.mark_modified(worksheet)
# Set edit link if marked for editing and start/end set.
# This prevents accidents / clicking the wrong row and provides
# feedback that sheet sync is still working.
# Also clear it if it shouldn't be set.
edit_link = self.edit_url.format(row['id']) if row['marked_for_edit'] == '[+] Marked' else ''
if row['edit_link'] != edit_link:
logging.info("Updating sheet row {} with edit link {}".format(row['id'], edit_link))
self.middleware.write_value(
worksheet, row,
"edit_link", edit_link,
)
self.middleware.mark_modified(worksheet)
class PlaylistSync: class PlaylistSync:
@ -382,10 +368,10 @@ def main(dbconnect, sheets_creds_file, edit_url, bustime_start, sheet_id, worksh
client_secret=sheets_creds['client_secret'], client_secret=sheets_creds['client_secret'],
refresh_token=sheets_creds['refresh_token'], refresh_token=sheets_creds['refresh_token'],
) )
sheets_middleware = SheetsMiddleware(sheets_client, sheet_id, worksheet_names, bustime_start, allocate_ids) sheets_middleware = SheetsMiddleware(sheets_client, sheet_id, worksheet_names, bustime_start, edit_url, allocate_ids)
workers = [ workers = [
SheetSync(sheets_middleware, stop, dbmanager, edit_url), SheetSync(sheets_middleware, stop, dbmanager),
] ]
if playlist_worksheet: if playlist_worksheet:
workers.append(PlaylistSync(stop, dbmanager, sheets_client, sheet_id, playlist_worksheet)) workers.append(PlaylistSync(stop, dbmanager, sheets_client, sheet_id, playlist_worksheet))

@ -85,11 +85,12 @@ class SheetsMiddleware():
# If playlist_worksheet is defined, add 1 to len(worksheets). # If playlist_worksheet is defined, add 1 to len(worksheets).
# For current values, this is 100/5 * 2 + 100/5/4 * 7 = 75 # For current values, this is 100/5 * 2 + 100/5/4 * 7 = 75
def __init__(self, client, sheet_id, worksheets, bustime_start, allocate_ids=False): def __init__(self, client, sheet_id, worksheets, bustime_start, edit_url, allocate_ids=False):
self.client = client self.client = client
self.sheet_id = sheet_id self.sheet_id = sheet_id
# map {worksheet: last modify time} # map {worksheet: last modify time}
self.worksheets = {w: 0 for w in worksheets} self.worksheets = {w: 0 for w in worksheets}
self.edit_url = edit_url
self.allocate_ids = allocate_ids self.allocate_ids = allocate_ids
# Maps DB column names (or general identifier, for non-DB columns) to sheet column indexes. # Maps DB column names (or general identifier, for non-DB columns) to sheet column indexes.
# Hard-coded for now, future work: determine this from column headers in sheet # Hard-coded for now, future work: determine this from column headers in sheet
@ -183,6 +184,18 @@ class SheetsMiddleware():
str(row['id']), str(row['id']),
) )
# Set edit link if marked for editing and start/end set.
# This prevents accidents / clicking the wrong row and provides
# feedback that sheet sync is still working.
# Also clear it if it shouldn't be set.
# We do this here instead of in sync_row() because it's Sheets-specific logic
# that doesn't depend on the DB event in any way.
edit_link = self.edit_url.format(row['id']) if row['marked_for_edit'] == '[+] Marked' else ''
if row['edit_link'] != edit_link:
logging.info("Updating sheet row {} with edit link {}".format(row['id'], edit_link))
self.write_value(worksheet, row, "edit_link", edit_link)
self.mark_modified(worksheet)
yield row yield row
def parse_row(self, worksheet, row_index, row): def parse_row(self, worksheet, row_index, row):

Loading…
Cancel
Save