From bda9561178af026426703154692fed9d1552e4ef Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Thu, 5 May 2022 16:41:55 -0400 Subject: [PATCH] type annotations --- scribe/blockchain/service.py | 4 ++-- scribe/elasticsearch/service.py | 5 ++++- scribe/hub/service.py | 7 +++++-- scribe/hub/session.py | 4 ++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/scribe/blockchain/service.py b/scribe/blockchain/service.py index 10b2e7c..865c859 100644 --- a/scribe/blockchain/service.py +++ b/scribe/blockchain/service.py @@ -19,7 +19,7 @@ from scribe.blockchain.mempool import MemPool from scribe.schema.url import normalize_name from scribe.service import BlockchainService if typing.TYPE_CHECKING: - from scribe.env import Env + from scribe.blockchain.env import BlockchainEnv from scribe.db.revertable import RevertableOpStack @@ -43,7 +43,7 @@ class BlockchainProcessorService(BlockchainService): "reorg_count", "Number of reorgs", namespace=NAMESPACE ) - def __init__(self, env: 'Env'): + def __init__(self, env: 'BlockchainEnv'): super().__init__(env, secondary_name='', thread_workers=1, thread_prefix='block-processor') self.daemon = LBCDaemon(env.coin, env.daemon_url) self.mempool = MemPool(env.coin, self.db) diff --git a/scribe/elasticsearch/service.py b/scribe/elasticsearch/service.py index f22c195..9476d5b 100644 --- a/scribe/elasticsearch/service.py +++ b/scribe/elasticsearch/service.py @@ -13,13 +13,16 @@ from scribe.elasticsearch.notifier_protocol import ElasticNotifierProtocol from scribe.elasticsearch.search import IndexVersionMismatch, expand_query from scribe.elasticsearch.constants import ALL_FIELDS, INDEX_DEFAULT_SETTINGS from scribe.elasticsearch.fast_ar_trending import FAST_AR_TRENDING_SCRIPT +if typing.TYPE_CHECKING: + from scribe.elasticsearch.env import ElasticEnv class ElasticSyncService(BlockchainReaderService): VERSION = 1 - def __init__(self, env): + def __init__(self, env: 'ElasticEnv'): super().__init__(env, 'lbry-elastic-writer', thread_workers=1, thread_prefix='lbry-elastic-writer') + self.env = env # self._refresh_interval = 0.1 self._task = None self.index = self.env.es_index_prefix + 'claims' diff --git a/scribe/hub/service.py b/scribe/hub/service.py index afeef59..ccc4d33 100644 --- a/scribe/hub/service.py +++ b/scribe/hub/service.py @@ -1,5 +1,5 @@ import time - +import typing import asyncio from scribe.blockchain.daemon import LBCDaemon from scribe.hub.session import SessionManager @@ -7,11 +7,14 @@ from scribe.hub.mempool import HubMemPool from scribe.hub.udp import StatusServer from scribe.service import BlockchainReaderService from scribe.elasticsearch import ElasticNotifierClientProtocol +if typing.TYPE_CHECKING: + from scribe.hub.env import ServerEnv class HubServerService(BlockchainReaderService): - def __init__(self, env): + def __init__(self, env: 'ServerEnv'): super().__init__(env, 'lbry-reader', thread_workers=max(1, env.max_query_workers), thread_prefix='hub-worker') + self.env = env self.notifications_to_send = [] self.mempool_notifications = set() self.status_server = StatusServer() diff --git a/scribe/hub/session.py b/scribe/hub/session.py index 896002b..e350d5c 100644 --- a/scribe/hub/session.py +++ b/scribe/hub/session.py @@ -28,7 +28,7 @@ from scribe.hub.common import BatchRequest, ProtocolError, Request, Batch, Notif from scribe.hub.framer import NewlineFramer if typing.TYPE_CHECKING: from scribe.db import HubDB - from scribe.env import Env + from scribe.hub.env import ServerEnv from scribe.blockchain.daemon import LBCDaemon from scribe.hub.mempool import HubMemPool @@ -164,7 +164,7 @@ class SessionManager: namespace=NAMESPACE, buckets=HISTOGRAM_BUCKETS ) - def __init__(self, env: 'Env', db: 'HubDB', mempool: 'HubMemPool', + def __init__(self, env: 'ServerEnv', db: 'HubDB', mempool: 'HubMemPool', daemon: 'LBCDaemon', shutdown_event: asyncio.Event, on_available_callback: typing.Callable[[], None], on_unavailable_callback: typing.Callable[[], None]): env.max_send = max(350000, env.max_send)