From 09fc44c76a8bf4ea4d2479c680a119138978d5fc Mon Sep 17 00:00:00 2001 From: AvishaiW Date: Tue, 21 Aug 2018 21:10:09 +0300 Subject: [PATCH] BLD: non existing id handling on status request --- catalyst/__main__.py | 36 ++++++++++++++++++---------------- catalyst/utils/remote_utils.py | 11 +++++++++-- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/catalyst/__main__.py b/catalyst/__main__.py index 752169903..e3f5ed0eb 100644 --- a/catalyst/__main__.py +++ b/catalyst/__main__.py @@ -744,25 +744,27 @@ def remote_status(ctx, algo_id, data_output, log_output): if algo_id is None: ctx.fail("must specify an id of your running algorithm with '--id'") - click.echo('Running in backtesting mode.', sys.stdout) - - perf, log = get_remote_status( + status_response = get_remote_status( algo_id=algo_id ) - - if log_output == '-': - click.echo(str(log), sys.stdout) - elif log_output != os.devnull: - with open(log_output, 'w') as file: - file.write(log) - - if data_output == '-' or perf is None: - click.echo('the performance data is:\n' + str(perf), sys.stdout) - elif data_output != os.devnull: - # make the catalyst magic not write any data - perf.to_pickle(data_output) - - return perf + if isinstance(status_response, tuple): + status, perf, log= status_response + if log_output == '-': + click.echo(str(log), sys.stderr) + elif log_output != os.devnull: + with open(log_output, 'w') as file: + file.write(log) + + if data_output == '-' or perf is None: + click.echo('the performance data is:\n' + str(perf), sys.stdout) + elif data_output != os.devnull: + # make the catalyst magic not write any data + perf.to_pickle(data_output) + print(status) + return status, perf + else: + print(status_response) + return status_response # @main.command(name='serve-live') diff --git a/catalyst/utils/remote_utils.py b/catalyst/utils/remote_utils.py index 45eace389..a9f39be70 100644 --- a/catalyst/utils/remote_utils.py +++ b/catalyst/utils/remote_utils.py @@ -13,6 +13,7 @@ POST = 'POST' GET = 'GET' +NONEXISTENT = 'nonexistent' EXCEPTION_LOG = "please contact Catalyst support to fix this issue at\n" \ "https://github.com/enigmampc/catalyst/issues/" @@ -63,6 +64,12 @@ def decompress_data(encoded_data): def handle_status(received_content): + status = received_content['status'] + if status == NONEXISTENT: + log.error(received_content['message']) + return status + log.info("The status of the algorithm is: '{}'". - format(received_content['status'])) - return load_response(received_content) + format(status)) + perf, log_file = load_response(received_content) + return status, perf, log_file