Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add run-jvm #6

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions gears_cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,43 @@ def run(host, port, password, requirements, filepath, extra_args):
for i in range(len(errors)):
print(Colors.Bred('%d)\t%s' % (i + 1, str(errors[i]))))

@gears_cli.command(help='Run JVM gears function')
@click.option('--host', default='localhost', help='Redis host to connect to')
@click.option('--port', default=6379, type=int, help='Redis port to connect to')
@click.option('--password', default=None, help='Redis password')
@click.argument('main')
@click.argument('filepath')
@click.argument('extra_args', nargs=-1, type=click.UNPROCESSED)
def run_jvm(host, port, password, main, filepath, extra_args):
r = create_connection(host, port, password);

extra_args = list(extra_args)

with open(filepath, 'rb') as f:
jar = f.read()
q = ['rg.jexecute', main, jar] + extra_args

try:
reply = r.execute_command(*q)
except Exception as e:
print(Colors.Bred("failed running gear function (%s)" % str(e)))
exit(1)

if reply == 'OK':
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to combine it to a function as it also appears in the 'run' function, but we can do it after ...

print('OK')
else:
results, errors = reply
print(Colors.Bold('Results'))
print(Colors.Bold('-------'))
for i in range(len(results)):
print_res(results[i], i + 1)
print('')
if len(errors) > 0:
print(Colors.Bred('Errors'))
print(Colors.Bred('------'))
for i in range(len(errors)):
print(Colors.Bred('%d)\t%s' % (i + 1, str(errors[i]))))

def decode_utf(d):
if isinstance(d, bytes):
return d.decode('utf-8')
Expand Down