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
|
||||
|
||||
|
||||
@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):
|
||||
data = celery.call('tokens', token_symbols, proof=proof)
|
||||
data = celery.call('tokens', token_symbols,
|
||||
catch=len(token_symbols), proof=proof)
|
||||
if data:
|
||||
return Token.new(data)
|
||||
tokens = []
|
||||
for token in data:
|
||||
print(f"Token: {token}")
|
||||
tokens.append(Token.new(token))
|
||||
return tokens
|
||||
return None
|
||||
|
||||
|
||||
|
@ -23,8 +23,8 @@ redis_port = config.get('REDIS_PORT')
|
||||
redis_db = config.get('REDIS_DB')
|
||||
|
||||
|
||||
def call(method, *args, **kwargs):
|
||||
""" Creates a redis channel and calls `cic_eth.api` with the provided `method` and `*args`. Returns the result of the api call
|
||||
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. Catch allows you to specify how many messages to catch before returning.
|
||||
"""
|
||||
log.debug(f"Using chainspec: {chain_spec}")
|
||||
redis_channel = str(uuid.uuid4())
|
||||
@ -43,21 +43,27 @@ def call(method, *args, **kwargs):
|
||||
|
||||
ps.get_message()
|
||||
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:
|
||||
sys.stderr.write(
|
||||
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
|
||||
|
||||
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()
|
||||
try:
|
||||
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
|
||||
return data
|
||||
|
@ -2,7 +2,6 @@ pytest==6.0.1
|
||||
pytest-celery==0.0.0a1
|
||||
pytest-mock==3.3.1
|
||||
pytest-cov==2.10.1
|
||||
pytest-localserver==0.5.1
|
||||
pytest-redis==2.0.0
|
||||
redis==3.5.3
|
||||
eth-tester==0.5.0b3
|
||||
|
@ -49,22 +49,30 @@ def test_tokens():
|
||||
|
||||
log.debug(f"tokens response {response}")
|
||||
tokens = response.json()
|
||||
assert tokens == {
|
||||
'address': '3ff776b6f888980def9d4220858803f9dc5e341e',
|
||||
assert tokens == [
|
||||
{'address': '3ff776b6f888980def9d4220858803f9dc5e341e',
|
||||
'converters': [],
|
||||
'decimals': 6,
|
||||
'name': 'Giftable Token',
|
||||
'proofs': ['3af82fa124235f84e78145f008054b11fe477e2b043ac5e4979c3afa737fd328'],
|
||||
'proofs_with_signers': [{'proof': '3af82fa124235f84e78145f008054b11fe477e2b043ac5e4979c3afa737fd328',
|
||||
'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():
|
||||
# Default Token
|
||||
response = client.get('/default_token',
|
||||
)
|
||||
response = client.get('/default_token')
|
||||
log.debug(f"balance response {response}")
|
||||
default_token = response.json()
|
||||
|
||||
|
@ -205,6 +205,7 @@ services:
|
||||
if [[ -f /tmp/cic/config/env_reset ]]; then source /tmp/cic/config/env_reset; fi
|
||||
set +a
|
||||
python -m cic_eth.runnable.daemons.server
|
||||
|
||||
cic-eth-tracker:
|
||||
image: ${IMAGE_BASE_URL:-registry.gitlab.com/grassrootseconomics/cic-internal-integration}/cic-eth:${TAG:-latest}
|
||||
build:
|
||||
|
Loading…
Reference in New Issue
Block a user