From 2ea3c1e50bfa510d3400986b61afc4d32e11a2f9 Mon Sep 17 00:00:00 2001 From: Kelvin Moutet Date: Wed, 19 Feb 2020 09:05:50 +0100 Subject: [PATCH] Update fabric-sdk and set up new features --- backend/requirements.txt | 2 +- backend/substrapp/ledger_utils.py | 12 ++++-------- backend/substrapp/tasks/utils.py | 6 +++--- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/backend/requirements.txt b/backend/requirements.txt index 388d69b28..185d00c7c 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -29,4 +29,4 @@ tldextract==2.2.2 uwsgi==2.0.18 zxcvbn==4.4.28 boto3==1.11.9 -git+git://github.com/hyperledger/fabric-sdk-py.git@df19cf51ff4f21507869184901988c094658367a +git+git://github.com/hyperledger/fabric-sdk-py.git@5f6407810f07c6901b10cd3b518dd82aed7482fb diff --git a/backend/substrapp/ledger_utils.py b/backend/substrapp/ledger_utils.py index a378d6296..61d54c2f8 100644 --- a/backend/substrapp/ledger_utils.py +++ b/backend/substrapp/ledger_utils.py @@ -144,13 +144,6 @@ def _wrapper(*args, **kwargs): return _retry -async def close_grpc_channels(client): - for name in client.peers: - await client.peers[name]._channel.close() - for name in client.orderers: - await client.orderers[name]._channel.close() - - @contextlib.contextmanager def get_hfc(): loop, client = LEDGER['hfc']() @@ -158,7 +151,7 @@ def get_hfc(): yield (loop, client) finally: loop.run_until_complete( - close_grpc_channels(client) + client.close_grpc_channels() ) del client loop.close() @@ -291,6 +284,9 @@ def call_ledger(call_type, fcn, *args, **kwargs): def _invoke_ledger(fcn, args=None, cc_pattern=None, sync=False, only_pkhash=True): params = { 'wait_for_event': sync, + 'grpc_broker_unavailable_retry': 5, + 'grpc_broker_unavailable_retry_delay': 3000, + 'raise_broker_unavailable': False } if sync: diff --git a/backend/substrapp/tasks/utils.py b/backend/substrapp/tasks/utils.py index 69afc962b..50f84b5e8 100644 --- a/backend/substrapp/tasks/utils.py +++ b/backend/substrapp/tasks/utils.py @@ -12,7 +12,7 @@ from kubernetes import client, config -CELERYWORKER_IMAGE = os.environ.get('CELERYWORKER_IMAGE') +CELERYWORKER_IMAGE = os.environ.get('CELERYWORKER_IMAGE', 'substrafoundation/celeryworker:latest') DOCKER_LABEL = 'substra_task' logger = logging.getLogger(__name__) @@ -61,7 +61,7 @@ def get_cpu_count(client): task_args = { 'image': CELERYWORKER_IMAGE, - 'command': 'python3 -u -c "import os; print(os.cpu_count(), end=\'\')"', + 'command': 'python3 -u -c "import os; print(os.cpu_count())"', 'detach': False, 'stdout': True, 'stderr': True, @@ -76,7 +76,7 @@ def get_cpu_count(client): cpu_count = os.cpu_count() try: - cpu_count_bytes = client.containers.run(**task_args) + cpu_count_bytes = client.containers.run(**task_args).strip() except (docker.errors.ContainerError, docker.errors.ImageNotFound, docker.errors.APIError): logger.info('[Warning] Cannot get cpu count from remote') else: