Skip to content

Commit

Permalink
Merge pull request #164 from SubstraFoundation/update-fabric-sdk
Browse files Browse the repository at this point in the history
Update fabric-sdk and set up new features
  • Loading branch information
Kelvin-M authored Feb 25, 2020
2 parents 7a58c60 + 2ea3c1e commit 8feae9f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 4 additions & 8 deletions backend/substrapp/ledger_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,14 @@ 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']()
try:
yield (loop, client)
finally:
loop.run_until_complete(
close_grpc_channels(client)
client.close_grpc_channels()
)
del client
loop.close()
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions backend/substrapp/tasks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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,
Expand All @@ -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:
Expand Down

0 comments on commit 8feae9f

Please sign in to comment.