def query(ctx, q, schema_file, ignore_cycles, cache_file, cache_host, cache_port, cache_db, resource_cache, fragment_cache, host, port): check_init(ctx) q = q.replace("'", '"') if cache_file: path_parts = cache_file.split('/') cache_base = '/'.join(cache_file.split('/')[:-1]) cache_file = path_parts[-1] if resource_cache or fragment_cache: remote_cache = all([cache_host, cache_port, cache_db]) cache = RedisCache(redis_file=None if remote_cache else (cache_file or 'data.db'), base='.agora/store' if not cache_file else cache_base, path='', redis_host=cache_host, redis_db=cache_db, redis_port=cache_port) else: cache = None ctx.obj['gw'].data_cache = cache processor = GraphQLProcessor(ctx.obj['gw'], schema_path=schema_file, scholar=fragment_cache, host=host, port=port, follow_cycles=not ignore_cycles, base='.agora/store/fragments') res = processor.query(q) click.echo(jsonify(res.to_dict()))
def publish_gql(ctx, schema_file, ignore_cycles, cache_file, cache_host, cache_port, cache_db, resource_cache, fragment_cache, age_gql_cache, len_gql_cache, host, port): check_init(ctx) if cache_file: path_parts = cache_file.split('/') cache_base = '/'.join(cache_file.split('/')[:-1]) cache_file = path_parts[-1] if resource_cache or fragment_cache: remote_cache = all([cache_host, cache_port, cache_db]) cache = RedisCache( redis_file=None if remote_cache else (cache_file or 'data.db'), base='.agora/store' if not cache_file else cache_base, path='', redis_host=cache_host, redis_db=cache_db, redis_port=cache_port) else: cache = None app = Flask(__name__) CORS(app) ctx.obj['gw'].data_cache = cache gql_processor = GraphQLProcessor(ctx.obj['gw'], schema_path=schema_file, scholar=fragment_cache, host=host, port=80, follow_cycles=not ignore_cycles, base='.agora/store/fragments', data_gw_cache={ 'max_age_seconds': age_gql_cache, 'max_len': len_gql_cache }) app.add_url_rule('/graphql', view_func=AgoraGraphQLView.as_view( 'graphql', schema=gql_processor.schema, executor=gql_processor.executor, middleware=gql_processor.middleware, graphiql=True)) options = { 'bind': '%s:%s' % ('0.0.0.0', str(port)), 'workers': 1, 'threads': number_of_workers(), 'workerconnections': 1000, 'timeout': 4000, 'workerclass': 'gthread', 'errorlog': '-', 'accesslog': '-' } GQLApplication(app, options).run()
def query(ctx, q, arg, incremental, ignore_cycles, cache_file, cache_host, cache_port, cache_db, resource_cache, fragment_cache, host, port): check_init(ctx) args = dict(map(lambda a: split_arg(a), arg)) if cache_file: path_parts = cache_file.split('/') cache_base = '/'.join(cache_file.split('/')[:-1]) cache_file = path_parts[-1] if resource_cache or fragment_cache: remote_cache = all([cache_host, cache_port, cache_db]) cache = RedisCache( redis_file=None if remote_cache else (cache_file or 'data.db'), base='.agora/store' if not cache_file else cache_base, path='', redis_host=cache_host, redis_db=cache_db, redis_port=cache_port) else: cache = None stop = Semaphore() queue = Queue() dgw = ctx.obj['gw'].data(q, cache=cache, lazy=False, host=host, port=port, base='.agora/store/fragments') gen = dgw.query(q, incremental=incremental, stop_event=stop, scholar=fragment_cache, follow_cycles=not ignore_cycles, **args) request_status = {'completed': False, 'exception': None} stream_th = Thread(target=gen_thread, args=(request_status, queue, gen)) stream_th.daemon = False stream_th.start() for chunk in gen_queue(request_status, stop, queue): click.echo(chunk, nl=False) click.echo()
def publish_ui(ctx, query, incremental, ignore_cycles, cache_file, cache_host, cache_port, cache_db, resource_cache, fragment_cache, host, port): check_init(ctx) if cache_file: path_parts = cache_file.split('/') cache_base = '/'.join(cache_file.split('/')[:-1]) cache_file = path_parts[-1] if resource_cache or fragment_cache: remote_cache = all([cache_host, cache_port, cache_db]) cache = RedisCache( redis_file=None if remote_cache else (cache_file or 'data.db'), base='.agora/store' if not cache_file else cache_base, path='', redis_host=cache_host, redis_db=cache_db, redis_port=cache_port) else: cache = None click.echo('Discovering ecosystem...', nl=False) dgw = ctx.obj['gw'].data(query, cache=cache, lazy=False, host=host, port=80, base='.agora/store/fragments') click.echo('Done') server = fs(ctx.obj['gw'].agora.fountain) frs(ctx.obj['gw'].agora, server=server, fragment_function=fragment_f(dgw, fragment_cache, ignore_cycles)) ss(ctx.obj['gw'].agora, server=server, query_function=query_f(dgw, incremental, fragment_cache, ignore_cycles)) CORS(server) server.run(host='0.0.0.0', port=port, threaded=True) click.echo()
def discover(ctx): check_init(ctx)
def export(ctx): check_init(ctx) compress('.agora', 'agora.zip')
def compute(ctx): check_init(ctx)
def delete(ctx): check_init(ctx)
def gql(ctx): check_init(ctx)
def list(ctx): check_init(ctx)
def publish(ctx): check_init(ctx)
def learn(ctx): check_init(ctx)
def add(ctx): check_init(ctx)
def get(ctx): check_init(ctx)
def show(ctx): check_init(ctx)