def fame_refresh(data, context):
    """Pubsub Google cloud function. Refreshes repos."""
    try:
        attrs = data['attributes']
        command = attrs.get('command', None)
        error_if_false(Refresh.is_valid(command),
                       'Invalid command %s' % command)

        sourcerer_origin = os.environ.get('sourcerer_origin', None)
        error_if_false(sourcerer_origin, 'Sourcerer origin is required')
        sourcerer_api_origin = os.environ.get('sourcerer_api_origin', None)
        sourcerer_api_secret = os.environ.get('sourcerer_api_secret', None)
        if os.environ.get('no_ssl_host_check', None) == '1':
            fame.ssl_hack.disable_ssl_host_check()

        configure_storage()
        topic = get_fame_pubsub_topic()  # Let it fail early.

        if command == Refresh.REFRESH_ALL:  # Enqueue refresh for all repos.
            client = pubsub.PublisherClient()
            for user, owner, repo, _, _, _ in RepoTracker.list():
                client.publish(topic, b'', command=Refresh.REFRESH,
                               user=user, owner=owner, repo=repo)
                print('i Enqueued for refresh %s:%s/%s' % (user, owner, repo))

        elif command == Refresh.REFRESH:  # Do an actual refresh for a repo.
            user = attrs.get('user', None)
            error_if_false(user, 'User is required')

            owner = attrs.get('owner', None)
            error_if_false(owner, 'Repo owner is required')

            repo = attrs.get('repo', None)
            error_if_false(repo, 'Repo is required')

            tracker = RepoTracker()
            tracker.configure(user, owner, repo,
                              sourcerer_api_origin=sourcerer_api_origin,
                              sourcerer_api_secret=sourcerer_api_secret)
            tracker.update()

            glory = Glory(sourcerer_origin, sourcerer_api_origin)
            glory.make(tracker.load())

    except Exception as e:
        print('e %s' % str(e))
Pubsub Google cloud function. Refreshes repos.
main.py