add catch to celery wrapper
This commit is contained in:
parent
cbc1b449ba
commit
ea1198a898
@ -114,11 +114,16 @@ def token(token_symbol: str, proof: Optional[str] = None):
|
|||||||
return token
|
return token
|
||||||
|
|
||||||
|
|
||||||
@app.get("/tokens", response_model=Token)
|
@app.get("/tokens", response_model=List[Token])
|
||||||
def tokens(token_symbols: Optional[List[str]] = Query(None), proof: Optional[Union[str, List[str], List[List[str]]]] = None):
|
def tokens(token_symbols: Optional[List[str]] = Query(None), proof: Optional[Union[str, List[str], List[List[str]]]] = None):
|
||||||
data = celery.call('tokens', token_symbols, proof=proof)
|
data = celery.call('tokens', token_symbols,
|
||||||
|
catch=len(token_symbols), proof=proof)
|
||||||
if data:
|
if data:
|
||||||
return Token.new(data)
|
tokens = []
|
||||||
|
for token in data:
|
||||||
|
print(f"Token: {token}")
|
||||||
|
tokens.append(Token.new(token))
|
||||||
|
return tokens
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,8 +23,8 @@ redis_port = config.get('REDIS_PORT')
|
|||||||
redis_db = config.get('REDIS_DB')
|
redis_db = config.get('REDIS_DB')
|
||||||
|
|
||||||
|
|
||||||
def call(method, *args, **kwargs):
|
def call(method, *args, catch=1, **kwargs):
|
||||||
""" Creates a redis channel and calls `cic_eth.api` with the provided `method` and `*args`. Returns the result of the api call
|
""" Creates a redis channel and calls `cic_eth.api` with the provided `method` and `*args`. Returns the result of the api call. Catch allows you to specify how many messages to catch before returning.
|
||||||
"""
|
"""
|
||||||
log.debug(f"Using chainspec: {chain_spec}")
|
log.debug(f"Using chainspec: {chain_spec}")
|
||||||
redis_channel = str(uuid.uuid4())
|
redis_channel = str(uuid.uuid4())
|
||||||
@ -43,21 +43,27 @@ def call(method, *args, **kwargs):
|
|||||||
|
|
||||||
ps.get_message()
|
ps.get_message()
|
||||||
try:
|
try:
|
||||||
o = ps.get_message(timeout=config.get('REDIS_TIMEOUT'))
|
data = []
|
||||||
|
if catch == 1:
|
||||||
|
message = ps.get_message(timeout=config.get('REDIS_TIMEOUT'))
|
||||||
|
data = json.loads(message['data'])["result"]
|
||||||
|
else:
|
||||||
|
for _i in range(catch):
|
||||||
|
message = ps.get_message(timeout=config.get('REDIS_TIMEOUT'))
|
||||||
|
result = json.loads(message['data'])["result"]
|
||||||
|
data.append(result)
|
||||||
|
|
||||||
except TimeoutError as e:
|
except TimeoutError as e:
|
||||||
sys.stderr.write(
|
sys.stderr.write(
|
||||||
f"cic_eth.api.{method}({args}, {kwargs}) timed out:\n {e}")
|
f"cic_eth.api.{method}({args}, {kwargs}) timed out:\n {e}")
|
||||||
|
raise e
|
||||||
|
except Exception as e:
|
||||||
|
sys.stderr.write(
|
||||||
|
f'Unable to parse Data:\n{data}\n Error:\n{e}')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
log.debug(
|
log.debug(
|
||||||
f"cic_eth.api.{method}(args={args}, kwargs={kwargs})\n {o}")
|
f"cic_eth.api.{method}(args={args}, kwargs={kwargs})\n {data}")
|
||||||
|
|
||||||
ps.unsubscribe()
|
ps.unsubscribe()
|
||||||
try:
|
return data
|
||||||
result = json.loads(o['data'])["result"]
|
|
||||||
return result
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
sys.stderr.write(
|
|
||||||
f'Unable to parse Data:\n{o}\n Error:\n{e}')
|
|
||||||
return None
|
|
||||||
|
@ -2,7 +2,6 @@ pytest==6.0.1
|
|||||||
pytest-celery==0.0.0a1
|
pytest-celery==0.0.0a1
|
||||||
pytest-mock==3.3.1
|
pytest-mock==3.3.1
|
||||||
pytest-cov==2.10.1
|
pytest-cov==2.10.1
|
||||||
pytest-localserver==0.5.1
|
|
||||||
pytest-redis==2.0.0
|
pytest-redis==2.0.0
|
||||||
redis==3.5.3
|
redis==3.5.3
|
||||||
eth-tester==0.5.0b3
|
eth-tester==0.5.0b3
|
||||||
|
@ -49,22 +49,30 @@ def test_tokens():
|
|||||||
|
|
||||||
log.debug(f"tokens response {response}")
|
log.debug(f"tokens response {response}")
|
||||||
tokens = response.json()
|
tokens = response.json()
|
||||||
assert tokens == {
|
assert tokens == [
|
||||||
'address': '3ff776b6f888980def9d4220858803f9dc5e341e',
|
{'address': '3ff776b6f888980def9d4220858803f9dc5e341e',
|
||||||
'converters': [],
|
'converters': [],
|
||||||
'decimals': 6,
|
'decimals': 6,
|
||||||
'name': 'Giftable Token',
|
'name': 'Giftable Token',
|
||||||
'proofs': ['3af82fa124235f84e78145f008054b11fe477e2b043ac5e4979c3afa737fd328'],
|
'proofs': ['3af82fa124235f84e78145f008054b11fe477e2b043ac5e4979c3afa737fd328'],
|
||||||
'proofs_with_signers': [{'proof': '3af82fa124235f84e78145f008054b11fe477e2b043ac5e4979c3afa737fd328',
|
'proofs_with_signers': [{'proof': '3af82fa124235f84e78145f008054b11fe477e2b043ac5e4979c3afa737fd328',
|
||||||
'signers': ['Eb3907eCad74a0013c259D5874AE7f22DcBcC95C']}],
|
'signers': ['Eb3907eCad74a0013c259D5874AE7f22DcBcC95C']}],
|
||||||
'symbol': 'GFT',
|
'symbol': 'GFT'},
|
||||||
}
|
{'address': '9c9506cf6c50f5b0371be72920fc6060d1a88a6a',
|
||||||
|
'converters': [],
|
||||||
|
'decimals': 6,
|
||||||
|
'name': 'Coffee',
|
||||||
|
'proofs': ['5b1549818725ca07c19fc47fda5d8d85bbebb1283855d5ab99785dcb7d9051d3'],
|
||||||
|
'proofs_with_signers': [{'proof': '5b1549818725ca07c19fc47fda5d8d85bbebb1283855d5ab99785dcb7d9051d3',
|
||||||
|
'signers': ['Eb3907eCad74a0013c259D5874AE7f22DcBcC95C',
|
||||||
|
'Eb3907eCad74a0013c259D5874AE7f22DcBcC95C']}],
|
||||||
|
'symbol': 'COFE'},
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def test_account():
|
def test_account():
|
||||||
# Default Token
|
# Default Token
|
||||||
response = client.get('/default_token',
|
response = client.get('/default_token')
|
||||||
)
|
|
||||||
log.debug(f"balance response {response}")
|
log.debug(f"balance response {response}")
|
||||||
default_token = response.json()
|
default_token = response.json()
|
||||||
|
|
||||||
|
@ -205,6 +205,7 @@ services:
|
|||||||
if [[ -f /tmp/cic/config/env_reset ]]; then source /tmp/cic/config/env_reset; fi
|
if [[ -f /tmp/cic/config/env_reset ]]; then source /tmp/cic/config/env_reset; fi
|
||||||
set +a
|
set +a
|
||||||
python -m cic_eth.runnable.daemons.server
|
python -m cic_eth.runnable.daemons.server
|
||||||
|
|
||||||
cic-eth-tracker:
|
cic-eth-tracker:
|
||||||
image: ${IMAGE_BASE_URL:-registry.gitlab.com/grassrootseconomics/cic-internal-integration}/cic-eth:${TAG:-latest}
|
image: ${IMAGE_BASE_URL:-registry.gitlab.com/grassrootseconomics/cic-internal-integration}/cic-eth:${TAG:-latest}
|
||||||
build:
|
build:
|
||||||
|
Loading…
Reference in New Issue
Block a user