#! /usr/bin/env python """ Dumb as rocks script to make it easy to run all dim refreshes with the appropriate contexts via Jenkins jobs. """ import json import subprocess # list of tuples representing dimensions to execute # (, or None) DIMS = [ ('accounting_report_currencies', None), ('booked_vendor_contract_snapshot', None), ('currency_exchange_rates', None), ('country', None), ('customer', None), ('genre', None), ('subgenre', None), ('label', None), ('owner', None), ('project', None), ('release_subgenre', None), ('subaccount', None), ('track_artist', { 'downstream_contexts': [{ 'flow': 'refresh', 'dim_type': 'track_artists_aggregated_temp'}]}), ('imprint', None), ('artist', { 'downstream_contexts': [{ 'flow': 'refresh', 'dim_type': 'canonical_track_metadata', 'downstream_contexts': [{ 'flow': 'refresh', 'dim_type': 'sound_recording_artist', 'downstream_contexts': [{ 'flow': 'dynamo_sync', 'dim_type': 'analytics_metadata' }] }] }]}) ] def execute_dim_flows(): """Execute SWF workflows necessary to refresh Snowflake dimension tables. Refreshes are kicked off via a command line call to `dim-refresh refresh -c `. """ for (dim_name, context) in DIMS: call = ['dim-refresh', 'refresh'] if context: call.extend(['-c', json.dumps(context, sort_keys=True)]) call.extend(['exec', dim_name]) subprocess.check_call(call) def execute_geocoding(): """Execute SWF workflows for geocoding Refreshes are kicked off via a command line call to `dim-refresh geocoding exec dim_zip`. """ # dim_name = 'dim_zip' context = None call = ['dim-refresh', 'geocoding'] if context: call.extend(['-c', json.dumps(context, sort_keys=True)]) call.extend(['exec', dim_name]) subprocess.check_call(call) if __name__ == "__main__": execute_dim_flows() execute_geocoding()