"""Utils for bootstraping the flow.""" from feed_sender.flows import helpers from feed_sender.flows.proper_changed_releases import config from feed_sender.util.aws import s3 as s3LocalUtils def _get_destination_s3_path(context_date): """Get full destination S3 path. Args: context_date (str): Context date. Returns: str: Full destination S3 path for changed releases file. """ destination_s3_path = config.CHANGED_RELEASES_S3_PATH.format( date=context_date) changed_releases_filename = config.CHANGED_RELEASES_FILENAME.format( date=context_date.replace('-', '_')) return '{}{}'.format(destination_s3_path, changed_releases_filename) def _get_destination_sftp_path(context_date): """Get full destination SFTP remote path. Note that this is a separated method from the one getting S3 path because SFTP path is still unknown. There can be special logic to get the destination SFTP path. If we confirm that later on code is going to be similar, we can combine the two methods. Args: context_date (str): Context date. Returns: str: Full destination SFTP path for changed releases file. """ destination_sftp_path = config.SFTP_REMOTE_PATH.format(date=context_date) changed_releases_filename = config.CHANGED_RELEASES_FILENAME.format( date=context_date.replace('-', '_')) return '{}{}'.format(destination_sftp_path, changed_releases_filename) def feed_already_sent(feed_name, context_date, s3_only=False): """Check if feed has really sent out. Feed has already sent out if changed release files exist on S3 and status is said to SENT. Args: feed_name (str): Name of the feed. context_date (str): Context date. s3_only (bool): True will skip the check for files on SFTP. Return: bool: True if feed has already been sent. """ # Check if changed releases files exist on S3. release_file_exist = s3LocalUtils.check_s3_key_exist( _get_destination_s3_path(context_date)) # Check if status is SENT in DynamoDB table. status_set_to_sent = helpers.get_status( feed_name, context_date) == helpers.STATUS_SENT checks = release_file_exist and status_set_to_sent return checks