Ejemplo n.º 1
0
def get_claim_check(block_id: str) -> dict:
    """Get a claim check that already exists (memoized)
    Args:
        block_id: the block id of the claim check to fetch
    Returns:
        Parsed claim check (as dict)
    """
    claim_check = redis.hget_sync("broadcast:claimcheck", block_id, decode=False)
    if claim_check is not None:
        return json.loads(claim_check)
    path = f"/claim-check?blockId={block_id}&dcId={keys.get_public_id()}"
    response = make_matchmaking_request("GET", path)
    new_claim_check = response.json()
    cache_claim_check(block_id, new_claim_check)
    return new_claim_check
Ejemplo n.º 2
0
def get_by_id(timing_id: str) -> "TimingEvent":
    """Return a TimingEvent instance located by ID.
    Args:
        timing_id: The id of a running timing event. Usually a contract_id
    Returns:
        Instantiated timingEvent instance if found
    Raises:
        exceptions.TimingEventSchedulerError if event is not found
    """
    result = redis.hget_sync(JOB_PARAMS_KEY, timing_id, decode=False)
    if not result:
        raise exceptions.TimingEventSchedulerError("NOT_FOUND")
    params = json.loads(result)
    return TimingEvent(timing_id=params["contract_id"],
                       seconds=params.get("seconds"),
                       cron=params.get("cron"))
Ejemplo n.º 3
0
def fire_if_exists(txn_id: str, transaction_model: transaction_model.TransactionModel) -> None:
    """ Fires a callback with a given payload, then removes from redis"""
    _log.debug(f"Looking in redis for callback: {CALLBACK_REDIS_KEY} {txn_id}")
    url = redis.hget_sync(CALLBACK_REDIS_KEY, txn_id)
    _log.debug(f"Found {url}")
    if url is not None:
        try:
            _log.debug(f"POST -> {url}")
            with requests.Session() as s:
                s.mount(url, requests.adapters.HTTPAdapter(max_retries=0))
                r = s.post(url, json=transaction_model.export_as_full(), timeout=10)
                _log.debug(f"POST <- {r.status_code}:{url}")
        except Exception:
            _log.exception("POST <- ERROR. No-op")

        redis.hdel_sync(CALLBACK_REDIS_KEY, txn_id)
Ejemplo n.º 4
0
 def test_hget(self):
     redis.hget_sync("banana", "banana")
     redis.redis_client.hget.assert_called_once_with("banana", "banana")