Skip to content

Commit

Permalink
Cache files can be located outside the .agora dir
Browse files Browse the repository at this point in the history
  • Loading branch information
fserena committed Sep 12, 2018
1 parent dd09387 commit 8ec3743
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 13 deletions.
7 changes: 6 additions & 1 deletion agora_cli/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,15 @@ def gen_queue(status, stop_event, queue):
@click.pass_context
def fragment(ctx, q, arg, ignore_cycles, cache_file, cache_host, cache_port, cache_db, resource_cache, fragment_cache, host, port):
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',
base='.agora/store' if not cache_file else cache_base,
path='',
redis_host=cache_host,
redis_db=cache_db,
Expand Down
2 changes: 1 addition & 1 deletion agora_cli/metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.0.9",
"version": "0.0.10",
"author": "Fernando Serena",
"email": "kudhmud@gmail.com",
"github": "https://github.com/fserena/agora-cli",
Expand Down
39 changes: 30 additions & 9 deletions agora_cli/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from agora.server.fragment import build as frs
from agora.server.planner import build as ps
from agora.server.sparql import build as ss
from agora_graphql.gql import GraphQLProcessor, AgoraExecutor
from agora_graphql.gql import GraphQLProcessor
from agora_graphql.server import AgoraGraphQLView
from agora_graphql.server.app import Application as GQLApplication
from agora_gw.server.app import Application
Expand Down Expand Up @@ -128,10 +128,15 @@ def publish_sparql(ctx, query, incremental, ignore_cycles, cache_file, cache_hos
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',
base='.agora/store' if not cache_file else cache_base,
path='',
redis_host=cache_host,
redis_db=cache_db,
Expand Down Expand Up @@ -170,14 +175,19 @@ def wrapper(*args, **kwargs):
@click.option('--port', default=80)
@click.pass_context
def publish_fragment(ctx, query, ignore_cycles, cache_file, cache_host, cache_port, cache_db, resource_cache,
fragment_cache, host,
port):
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',
base='.agora/store' if not cache_file else cache_base,
path='',
redis_host=cache_host,
redis_db=cache_db,
Expand Down Expand Up @@ -213,10 +223,15 @@ def publish_ui(ctx, query, incremental, ignore_cycles, cache_file, cache_host, c
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',
base='.agora/store' if not cache_file else cache_base,
path='',
redis_host=cache_host,
redis_db=cache_db,
Expand Down Expand Up @@ -247,14 +262,20 @@ def publish_ui(ctx, query, incremental, ignore_cycles, cache_file, cache_host, c
@click.option('--host', default='agora')
@click.option('--port', default=80)
@click.pass_context
def publish_gql(ctx, schema_file, ignore_cycles, cache_file, cache_host, cache_port, cache_db, resource_cache, fragment_cache, host,
def publish_gql(ctx, schema_file, 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',
base='.agora/store' if not cache_file else cache_base,
path='',
redis_host=cache_host,
redis_db=cache_db,
Expand All @@ -267,7 +288,7 @@ def publish_gql(ctx, schema_file, ignore_cycles, cache_file, cache_host, cache_p

ctx.obj['gw'].data_cache = cache
gql_processor = GraphQLProcessor(ctx.obj['gw'], schema_path=schema_file, scholar=fragment_cache, server_name=host,
port=80, follow_cycles=not ignore_cycles, base='.agora/store/fragments')
port=80, follow_cycles=not ignore_cycles, base='.agora/store/fragments')

app.add_url_rule('/graphql',
view_func=AgoraGraphQLView.as_view('graphql', schema=gql_processor.schema,
Expand Down
7 changes: 6 additions & 1 deletion agora_cli/qgl.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,15 @@ def query(ctx, q, schema_file, ignore_cycles, cache_file, cache_host, cache_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',
base='.agora/store' if not cache_file else cache_base,
path='',
redis_host=cache_host,
redis_db=cache_db,
Expand Down
7 changes: 6 additions & 1 deletion agora_cli/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,15 @@ def query(ctx, q, arg, incremental, ignore_cycles, cache_file, cache_host, cache

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',
base='.agora/store' if not cache_file else cache_base,
path='',
redis_host=cache_host,
redis_db=cache_db,
Expand Down

0 comments on commit 8ec3743

Please sign in to comment.