def wait_for_app_version_attribute()

in ebcli/operations/buildspecops.py [0:0]


def wait_for_app_version_attribute(app_name, version_labels, timeout=5):
    io.echo('--- Waiting for Application Versions to populate attributes ---')
    versions_to_check = list(version_labels)
    found = dict.fromkeys(version_labels)
    failed = dict.fromkeys(version_labels)
    start_time = utils.datetime_utcnow()
    timediff = timedelta(minutes=timeout)
    while versions_to_check:
        if _timeout_reached(start_time, timediff):
            io.log_error(
                strings['appversion.attribute.failed'].replace(
                    '{app_version}',
                    ', '.join(version_labels)
                )
            )
            return False
        io.LOG.debug('Retrieving app versions.')
        app_versions = elasticbeanstalk.get_application_versions(
            app_name,
            versions_to_check
        )['ApplicationVersions']
        for version in app_versions:
            if version.get('BuildArn'):
                found[version['VersionLabel']] = True
                io.echo(strings['appversion.attribute.success'].format(app_version=version['VersionLabel']))
                versions_to_check.remove(version['VersionLabel'])
            elif version.get('Status') == 'FAILED':
                failed[version['VersionLabel']] = True
                io.log_error(
                    strings['appversion.attribute.failed'].format(
                        app_version=version['VersionLabel']
                    )
                )
                versions_to_check.remove(version['VersionLabel'])

        if all(found.values()):
            return True

        _sleep()

    return not any(failed.values())