"""Functions to set and get feed statuses from the DynamoDB.""" from functools import wraps from feed_sender.flows import helpers def set_status(feed_name, status): """Set DynamoDB status. Applying this decorator to delete specific status item if parameter 'reload' is set to 'True'. Args: feed_name (str): feed name status (str): status of the feed generation process Returns: func """ def inner_wrapper(func): @wraps(func) def wrapper(activity, context_date): activity.logger.info('Update status for feed: {} {} '.format( feed_name, context_date)) helpers.set_status(feed_name, context_date, status) return func(activity, context_date) return wrapper return inner_wrapper def check_ingested(feed_name): """Check if status for feed generation for this feed is ingested. If status is ingested, this decorator will set the stop flag to true. Decider will check the flag and will stop the workflow. Args: feed_name (str): feed name Returns: func """ def inner_wrapper(func): @wraps(func) def wrapper(activity, context_date): current_status = helpers.get_status(feed_name, context_date) resp = func(activity, context_date) or {} if current_status == helpers.STATUS_SENT: resp['stop'] = True return resp return wrapper return inner_wrapper