示例#1
0
def sync_all():
    """Generate response for the GET request to /api/v1/sync_all."""
    current_app.logger.info("/api/v1/sync_all - %s" % dict(request.args))
    ecosystem_name = request.args.get('ecosystem', None)
    package_name = request.args.get('package', None)
    version_id = request.args.get('version', None)
    limit = request.args.get('limit', None)
    offset = request.args.get('offset', None)
    params = {
        "ecosystem": ecosystem_name,
        "package": package_name,
        "version": version_id,
        "limit": limit,
        "offset": offset
    }
    current_app.logger.info("params - %s" % params)

    data = data_importer.PostgresHandler().fetch_pending_epvs(**params)

    try:
        pending_list = data["pending_list"]
        report = data_importer.import_epv_from_s3_http(list_epv=pending_list)
        response = {
            'message': report.get('message'),
            'epv': pending_list,
            'count_imported_EPVs': report.get('count_imported_EPVs')
        }

        if report.get('status') is not 'Success':
            return flask.jsonify(response), 500
        else:
            return flask.jsonify(response)
    except RuntimeError:
        response = {'message': 'RuntimeError encountered', 'epv': pending_list}
        return flask.jsonify(response), 500
def pending():
    """Get request to enlist all the EPVs which are not yet synced to Graph."""
    app.logger.info("/api/v1/pending - %s" % dict(request.args))
    ecosystem_name = request.args.get('ecosystem', None)
    package_name = request.args.get('package', None)
    version_id = request.args.get('version', None)
    limit = request.args.get('limit', None)
    offset = request.args.get('offset', None)

    params = {"ecosystem": ecosystem_name, "package": package_name, "version": version_id,
              "limit": limit, "offset": offset}
    app.logger.info("params - %s" % params)

    pending_list = data_importer.PostgresHandler().fetch_pending_epvs(**params)

    return flask.jsonify(pending_list), 200