"""Dimension Refresh base flow. ======================== Base Dimension Refresh Flow class with useful properties for accessing configs. """ import logging import boto3 from botocore.config import Config from garcon import activity from dim_refresh_etl import conf from dim_refresh_etl.util import environment, sentry_utils logger = logging.getLogger('dim_refresh_etl') SWF_DOMAINS = { environment.PROD: 'prod_dim_refresh', environment.QA: 'qa_dim_refresh' } class BaseFlow(object): """Base flow class.""" def __init__(self, name, version): """Create a Dimension WorkFlow flow. Args: name (str): name of workflow. version (str): version of the workflow (ex 1.0). """ self.domain = SWF_DOMAINS.get(environment.name, 'dev') self.name = name self.version = version self.client = boto3.client('swf', config=Config( connect_timeout=60, region_name='us-east-1', read_timeout=180, retries={'max_attempts': 2} )) self.create = activity.create( self.client, self.domain, self.name, version=self.version, on_exception=self.on_exception) @property def conf_art_relations_db(self): """Get convenience property to get art_relations_db config. Returns: dict: art_relations credentials. """ return conf.getconf('mysql')['art_relations'] @property def conf_aws(self): """Get convenience property to get aws credentials. Returns: dict: aws credentials. """ return conf.getconf('aws')['aws'] @property def conf_sns_options(self): """Get convenience property to SNS config. For sync related commands. Returns: dict: contains SNS related configs. """ return conf.getconf('aws')['sns'] def decider(self, schedule, context): """Get decider.""" raise NotImplementedError() def on_exception(self, actor, exception): """Capture an exception that has occurred in the application. Args: actor (Activity, DeciderWorker): the actor that has received the exception. exception (Exception): the exception to capture. """ # client grabs sentry dns from SENTRY_DSN environment variable sentry_utils.capture_exception() if isinstance(actor, activity.Activity): actor.logger.error(exception, exc_info=True) else: logger.error(exception, exc_info=True) def workflow_id(self, context): """Get workflow ID.""" raise NotImplementedError()