"""Dim Record Refresh Tasks. ========================== Garcon task for recording results of a Dim Refresh. """ import json from garcon import task from dim_refresh_etl.util import import_utils # TODO(jpenner): make more generic and move to garcon contrib @task.decorate(timeout=7200) def trigger_workflow(activity, downstream_contexts): """Garcon task for generating refresh stats for current dim refresh. Args: activity (ActivityWorker): the activity worker. downstream_contexts (list): list of downstream dim refresh dictionary contexts to execute. """ for context in downstream_contexts: flow_class = import_utils.import_workflow_class(context['flow']) flow = flow_class() workflow_id = flow.workflow_id(context) activity.logger.info( 'Starting workflow {} on domain {} with id {}'.format( flow.name, flow.domain, workflow_id)) activity.client.start_workflow_execution( domain=flow.domain, workflowId=workflow_id, workflowType={'name': flow.name, 'version': flow.version}, taskList={'name': flow.name}, executionStartToCloseTimeout='7200', input=json.dumps(context))