def sync_updated_events(configuration, condition, don_t_run_too_long=False): updated = fusion_tables.select(configuration['master table'], condition=condition) logging.info("Syncing %d updated rows in %s master %s" % (len(updated), configuration['id'], configuration['master table'])) for row in updated: # old rows are not deleted! New slave rows are just added with incremented sequence number # create slave dicts (slaves, final_date) = fusion_tables.master_to_slave(row) # store slave dicts for slave in slaves: fusion_tables.insert_hold(configuration['slave table'], slave) # delete the old master row (the updated row was a copy!) condition = "'event slug' = '%s' and 'state' = 'public'" % row['event slug'] old = fusion_tables.select(configuration['master table'], cols=['rowid'], condition=condition) for old_row in old: # should be only a single row!! fusion_tables.delete_with_implicit_rowid(configuration['master table'], old_row) # set master event state to 'public' update = { 'rowid': row['rowid'], 'state': 'public', 'sync date': datetime.today().strftime(FUSION_TABLE_DATE_TIME_FORMAT), 'final date': final_date } fusion_tables.update_with_implicit_rowid(configuration['master table'], update) running_too_long(don_t_run_too_long) fusion_tables.insert_go(configuration['slave table']) logging.info("Done syncing updated rows in %s master %s" % (configuration['id'], configuration['master table']))
def sync_one_month_old_cancellations(configuration, condition): cancellation = fusion_tables.select(configuration['master table'], condition=condition) logging.info("Syncing %d cancellation rows in %s master %s" % (len(cancellation), configuration['id'], configuration['master table'])) for row in cancellation: # delete cancellation master rows fusion_tables.delete_with_implicit_rowid(configuration['master table'], row) logging.info("Done syncing cancellation rows in %s master %s" % (configuration['id'], configuration['master table'])) running_too_long(don_t_run_too_long=True)
def sync_events_with_final_date_passed(configuration, condition): outdated = fusion_tables.select(configuration['master table'], condition=condition) logging.info("Deleting %d finally past events in %s master (and slave) %s" % (len(outdated), configuration['id'], configuration['master table'])) for row in outdated: # delete old slave rows condition = "'event slug' = '%s'" % row['event slug'] slaves = fusion_tables.select(configuration['slave table'], cols=['rowid'], condition=condition, filter_obsolete_rows=False) logging.info("Deleting %d finally past events in %s slave %s" % (len(slaves), configuration['id'], configuration['slave table'])) delete_slaves(configuration['slave table'], slaves) # delete cancellation master rows fusion_tables.delete_with_implicit_rowid(configuration['master table'], row) running_too_long(don_t_run_too_long=True) logging.info("Done deleting finally past events in %s master (and slave) %s" % (configuration['id'], configuration['master table']))
def sync_updated_events(configuration, condition, don_t_run_too_long=False): updated = fusion_tables.select(configuration['master table'], condition=condition) logging.info( "Syncing %d updated rows in %s master %s" % (len(updated), configuration['id'], configuration['master table'])) for row in updated: # old rows are not deleted! New slave rows are just added with incremented sequence number # create slave dicts (slaves, final_date) = fusion_tables.master_to_slave(row) # store slave dicts for slave in slaves: fusion_tables.insert_hold(configuration['slave table'], slave) # delete the old master row (the updated row was a copy!) condition = "'event slug' = '%s' and 'state' = 'public'" % row[ 'event slug'] old = fusion_tables.select(configuration['master table'], cols=['rowid'], condition=condition) for old_row in old: # should be only a single row!! fusion_tables.delete_with_implicit_rowid( configuration['master table'], old_row) # set master event state to 'public' update = { 'rowid': row['rowid'], 'state': 'public', 'sync date': datetime.today().strftime(FUSION_TABLE_DATE_TIME_FORMAT), 'final date': final_date } fusion_tables.update_with_implicit_rowid(configuration['master table'], update) running_too_long(don_t_run_too_long) fusion_tables.insert_go(configuration['slave table']) logging.info("Done syncing updated rows in %s master %s" % (configuration['id'], configuration['master table']))
def sync_events_with_final_date_passed(configuration, condition): outdated = fusion_tables.select(configuration['master table'], condition=condition) logging.info( "Deleting %d finally past events in %s master (and slave) %s" % (len(outdated), configuration['id'], configuration['master table'])) for row in outdated: # delete old slave rows condition = "'event slug' = '%s'" % row['event slug'] slaves = fusion_tables.select(configuration['slave table'], cols=['rowid'], condition=condition, filter_obsolete_rows=False) logging.info( "Deleting %d finally past events in %s slave %s" % (len(slaves), configuration['id'], configuration['slave table'])) delete_slaves(configuration['slave table'], slaves) # delete cancellation master rows fusion_tables.delete_with_implicit_rowid(configuration['master table'], row) running_too_long(don_t_run_too_long=True) logging.info( "Done deleting finally past events in %s master (and slave) %s" % (configuration['id'], configuration['master table']))
def delete_slaves(tableId, slaves): for slave in slaves: fusion_tables.delete_with_implicit_rowid(tableId, slave)