def get_new_l4_blocks() -> List[bytes]: """Get all new l4 records from the incoming queue""" if LEVEL != "5": raise RuntimeError("Getting l4_blocks is a level 5 action") l4_blocks = [] for _ in range(0, redis.llen_sync(INCOMING_TX_KEY)): # These are in lists because enterprise will be able to specify more than one l4. l4_blocks_list = cast(bytes, redis.rpoplpush_sync(INCOMING_TX_KEY, PROCESSING_TX_KEY, decode=False)) l4_blocks.append(l4_blocks_list) return l4_blocks
def get_next_item() -> Optional[Any]: """Get and json.loads the next item from the queue""" item = cast(bytes, redis.rpoplpush_sync(INCOMING_TX_KEY, PROCESSING_TX_KEY, decode=False)) if item is not None: if LEVEL != "1": if item_is_expired(item): redis.lpop_sync(PROCESSING_TX_KEY, decode=False) return get_next_item() next_item = json.loads(item) _log.info(f"Next item: {next_item}") return next_item return None
def get_new_transactions() -> List[transaction_model.TransactionModel]: """Get all new transactions from the incoming queue""" if LEVEL != "1": raise RuntimeError("Getting transactions is a level 1 action") transactions = [] # Only allow up to 1000 transactions to process at a time length = min(redis.llen_sync(INCOMING_TX_KEY), 1000) for _ in range(0, length): string = cast(bytes, redis.rpoplpush_sync(INCOMING_TX_KEY, PROCESSING_TX_KEY, decode=False)) dictionary = json.loads(string) txn_model = transaction_model.new_from_queue_input(dictionary) transactions.append(txn_model) return transactions
def test_rpoplpush(self): redis.rpoplpush_sync("banana", "banana") redis.redis_client.rpoplpush.assert_called_once_with("banana", "banana")