def on_batch_committed(self, batch_id): with self._lock: key = self._pending_batches.pop(batch_id, None) if key is not None: if key.value < 1000000: txn = create_intkey_transaction(verb="inc", name=key.name, value=1, deps=[self._deps[key.name]], signer=self._signer) batch = create_batch(transactions=[txn], signer=self._signer) batch_id = batch.header_signature batch_list = batch_pb2.BatchList(batches=[batch]) (code, _) = post_batches(key.url, batch_list, auth_info=self._auth_info) if code == 202: with self._lock: self._pending_batches[batch.header_signature] = \ IntKeyState( name=key.name, url=key.url, value=key.value + 1) self.delegate.on_new_batch(batch_id, key.url) else: LOGGER.debug('Key %s completed', key.name) self._create_new_key()
def _create_new_key(self): with self._lock: url = random.choice(self._urls) if self._urls else None batch_id = None if url is not None: name = datetime.now().isoformat()[-20:] txn = create_intkey_transaction(verb="set", name=name, value=0, deps=[], signer=self._signer) batch = create_batch(transactions=[txn], signer=self._signer) self._deps[name] = txn.header_signature batch_id = batch.header_signature batch_list = batch_pb2.BatchList(batches=[batch]) (code, _) = post_batches(url, batch_list, auth_info=self._auth_info) if code == 202: with self._lock: self._pending_batches[batch_id] = \ IntKeyState(name=name, url=url, value=0) self.delegate.on_new_batch(batch_id, url)
def on_batch_committed(self, batch_id): with self._lock: key = self._pending_batches.pop(batch_id, None) if key is not None: if key.value < 1000000: txn = create_intkey_transaction(verb="inc", name=key.name, value=1, deps=[self._deps[key.name]], private_key=self._private_key, public_key=self._public_key) batch = create_batch(transactions=[txn], private_key=self._private_key, public_key=self._public_key) batch_id = batch.header_signature batch_list = batch_pb2.BatchList(batches=[batch]) key.stream.send( message_type=Message.CLIENT_BATCH_SUBMIT_REQUEST, content=batch_list.SerializeToString()) with self._lock: self._pending_batches[batch.header_signature] = \ IntKeyState( name=key.name, stream=key.stream, value=key.value + 1) self.delegate.on_new_batch(batch_id, key.stream) else: LOGGER.debug('Key %s completed', key.name) self._create_new_key()
def _create_new_key(self): with self._lock: stream = random.choice(self._streams) if \ len(self._streams) > 0 else None batch_id = None if stream is not None: name = datetime.now().isoformat() txn = create_intkey_transaction(verb="set", name=name, value=0, deps=[], private_key=self._private_key, public_key=self._public_key) batch = create_batch(transactions=[txn], private_key=self._private_key, public_key=self._public_key) self._deps[name] = txn.header_signature batch_id = batch.header_signature batch_list = batch_pb2.BatchList(batches=[batch]) stream.send(message_type=Message.CLIENT_BATCH_SUBMIT_REQUEST, content=batch_list.SerializeToString()) with self._lock: self._pending_batches[batch_id] = \ IntKeyState(name=name, stream=stream, value=0) self.delegate.on_new_batch(batch_id, stream)
def _create_new_key(self): with self._lock: url = random.choice(self._urls) if \ len(self._urls) > 0 else None batch_id = None if url is not None: name = datetime.now().isoformat() txn = create_intkey_transaction(verb="set", name=name, value=0, deps=[], private_key=self._private_key, public_key=self._public_key) batch = create_batch(transactions=[txn], private_key=self._private_key, public_key=self._public_key) self._deps[name] = txn.header_signature batch_id = batch.header_signature batch_list = batch_pb2.BatchList(batches=[batch]) post_batches(url, batch_list) with self._lock: self._pending_batches[batch_id] = \ IntKeyState(name=name, url=url, value=0) self.delegate.on_new_batch(batch_id, url)
def _create_new_key(self): with self._lock: url = random.choice(self._urls) if self._urls else None batch_id = None if url is not None: name = datetime.now().isoformat()[-20:] txn = create_intkey_transaction( verb="set", name=name, value=0, deps=[], signer=self._signer) batch = create_batch( transactions=[txn], signer=self._signer) self._deps[name] = txn.header_signature batch_id = batch.header_signature batch_list = batch_pb2.BatchList(batches=[batch]) (code, _) = post_batches(url, batch_list, auth_info=self._auth_info) if code == 202: with self._lock: self._pending_batches[batch_id] = \ IntKeyState(name=name, url=url, value=0) self.delegate.on_new_batch(batch_id, url)
def on_batch_committed(self, batch_id): with self._lock: key = self._pending_batches.pop(batch_id, None) if key is not None: if key.value < 1000000: txn = create_intkey_transaction( verb="inc", name=key.name, value=1, deps=[self._deps[key.name]], signer=self._signer) batch = create_batch( transactions=[txn], signer=self._signer) batch_id = batch.header_signature batch_list = batch_pb2.BatchList(batches=[batch]) (code, _) = post_batches(key.url, batch_list, auth_info=self._auth_info) if code == 202: with self._lock: self._pending_batches[batch.header_signature] = \ IntKeyState( name=key.name, url=key.url, value=key.value + 1) self.delegate.on_new_batch(batch_id, key.url) else: LOGGER.debug('Key %s completed', key.name) self._create_new_key()