Skip to content

Commit

Permalink
BLD: logging from server to client works properly with zmqHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
AvishaiW committed Jul 15, 2018
1 parent 7b7b378 commit 0ddc6c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
5 changes: 3 additions & 2 deletions catalyst/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,6 @@ def live(ctx,
@click.option(
'-o',
'--output',
default='-',
metavar='FILENAME',
show_default=True,
help="The location to write the perf data. If this is '-' the perf"
Expand Down Expand Up @@ -683,7 +682,7 @@ def run(ctx,
bundle_timestamp=bundle_timestamp,
start=start,
end=end,
output=output,
output='-',
print_algo=print_algo,
local_namespace=local_namespace,
environ=os.environ,
Expand All @@ -700,6 +699,8 @@ def run(ctx,

if output == '-':
click.echo(str(perf), sys.stdout)
elif output is None:
pass
elif output != os.devnull: # make the catalyst magic not write any data
perf.to_pickle(output)

Expand Down
23 changes: 10 additions & 13 deletions catalyst/utils/run_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@
import json
import zlib
import pickle

from logbook.queues import ZeroMQSubscriber
from logbook import StderrHandler


# adding the handlers which receive the records from the server
my_handler = StderrHandler()
subscriber = ZeroMQSubscriber(uri="tcp://34.202.72.107:5050")
# subscriber = ZeroMQSubscriber('tcp://127.0.0.1:5050', multi=True)
controller = subscriber.dispatch_in_background(my_handler)
# subscriber.dispatch_forever()
# subscriber = ZeroMQSubscriber(uri="tcp://127.0.0.1:5050")
controller = subscriber.dispatch_in_background()


def prepare_args(file, text):
"""
Expand Down Expand Up @@ -81,7 +76,7 @@ def run_server(
):

# address to send
url = 'https://sandbox2.enigma.co/api/catalyst/serve'
url = 'http://34.202.72.107:5000/api/catalyst/serve'
# url = 'http://127.0.0.1:5000/api/catalyst/serve'

# argument preparation - encode the file for transfer
Expand Down Expand Up @@ -124,10 +119,11 @@ def run_server(
json_file,
default=convert_date
),
verify=False
verify=False,
)

# close the handlers, which are not needed anymore
# controller.stop()
controller.stop()
subscriber.close()

if response.status_code == 500:
Expand All @@ -137,11 +133,12 @@ def run_server(
raise Exception("The server is down at the moment, please contact "
"Catalyst support to fix this issue at "
"https://github.com/enigmampc/catalyst/issues/")
elif response.status_code == 202:
print(response.json()['error'])
elif response.status_code == 202 or response.status_code == 400:
print(response.json()['error']) if response.json()['error'] else None

else: # if the run was successful
received_data = response.json()
data_perf_compressed = base64.b64decode(received_data["data"])
data_perf_pickled = zlib.decompress(data_perf_compressed)
data_perf = pickle.loads(data_perf_pickled)
print(data_perf)

0 comments on commit 0ddc6c4

Please sign in to comment.