mirror of
https://github.com/yzernik/squeaknode.git
synced 2026-08-18 13:09:08 +02:00
Add sync_interval_s config (#424)
This commit is contained in:
parent
efd12e8332
commit
2a0e861fb2
5 changed files with 18 additions and 19 deletions
|
|
@ -46,6 +46,7 @@ services:
|
|||
- WEBADMIN_ALLOW_CORS
|
||||
- NETWORK
|
||||
- LOG_LEVEL
|
||||
- SQUEAKNODE_SYNC_INTERVAL_S
|
||||
volumes:
|
||||
- shared:/rpc
|
||||
- ~/.lnd:/root/.lnd
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ class Config:
|
|||
self._configs['squeaknode_max_squeaks_per_address_per_hour'] = self._get_squeaknode_max_squeaks_per_address_per_hour()
|
||||
self._configs['squeaknode_database'] = self._get_squeaknode_database()
|
||||
self._configs['squeaknode_sqk_dir'] = self._get_squeaknode_sqk_dir()
|
||||
self._configs['squeaknode_enable_sync'] = self._get_squeaknode_enable_sync()
|
||||
self._configs['squeaknode_sync_interval_s'] = self._get_squeaknode_sync_interval_s()
|
||||
self._configs['squeaknode_log_level'] = self._get_squeaknode_log_level()
|
||||
|
||||
# db
|
||||
|
|
@ -191,9 +191,9 @@ class Config:
|
|||
def _get_squeaknode_sqk_dir(self):
|
||||
return self.parser.get("squeaknode", "sqk_dir", fallback=DEFAULT_SQK_DIR_PATH)
|
||||
|
||||
def _get_squeaknode_enable_sync(self):
|
||||
return environ.get('SQUEAKNODE_ENABLE_SYNC') \
|
||||
or self.parser.getboolean("squeaknode", "enable_sync", fallback=False)
|
||||
def _get_squeaknode_sync_interval_s(self):
|
||||
return int(environ.get('SQUEAKNODE_SYNC_INTERVAL_S')) \
|
||||
or self.parser.getint("squeaknode", "sync_interval_s", fallback=None)
|
||||
|
||||
def _get_squeaknode_log_level(self):
|
||||
return environ.get('LOG_LEVEL') \
|
||||
|
|
|
|||
|
|
@ -87,8 +87,8 @@ def load_max_squeaks_per_address_per_hour(config):
|
|||
return config.squeaknode_max_squeaks_per_address_per_hour
|
||||
|
||||
|
||||
def load_enable_sync(config):
|
||||
return config.squeaknode_enable_sync
|
||||
def load_sync_interval_s(config):
|
||||
return config.squeaknode_sync_interval_s
|
||||
|
||||
|
||||
def load_handler(squeak_node):
|
||||
|
|
@ -222,7 +222,7 @@ def run_server(config):
|
|||
blockchain_client = load_blockchain_client(config)
|
||||
|
||||
# load enable sync config
|
||||
enable_sync = load_enable_sync(config)
|
||||
sync_interval_s = load_sync_interval_s(config)
|
||||
|
||||
# Create and start the squeak node
|
||||
squeak_node = SqueakNode(
|
||||
|
|
@ -232,7 +232,7 @@ def run_server(config):
|
|||
lightning_host_port,
|
||||
price,
|
||||
max_squeaks_per_address_per_hour,
|
||||
enable_sync,
|
||||
sync_interval_s,
|
||||
)
|
||||
squeak_node.start_running()
|
||||
|
||||
|
|
|
|||
|
|
@ -39,14 +39,14 @@ class SqueakNode:
|
|||
lightning_host_port,
|
||||
price,
|
||||
max_squeaks_per_address_per_hour,
|
||||
enable_sync=False,
|
||||
sync_interval_s,
|
||||
):
|
||||
self.postgres_db = postgres_db
|
||||
self.blockchain_client = blockchain_client
|
||||
self.lightning_client = lightning_client
|
||||
self.lightning_host_port = lightning_host_port
|
||||
self.price = price
|
||||
self.enable_sync = enable_sync
|
||||
self.sync_interval_s = sync_interval_s
|
||||
self.squeak_block_verifier = SqueakBlockVerifier(postgres_db, blockchain_client)
|
||||
self.squeak_block_periodic_worker = SqueakBlockPeriodicWorker(
|
||||
self.squeak_block_verifier
|
||||
|
|
@ -77,6 +77,7 @@ class SqueakNode:
|
|||
)
|
||||
self.squeak_peer_sync_worker = SqueakPeerSyncWorker(
|
||||
self.squeak_sync_controller,
|
||||
self.sync_interval_s,
|
||||
)
|
||||
self.squeak_expired_offer_cleaner = SqueakExpiredOfferCleaner(
|
||||
self.postgres_db,
|
||||
|
|
@ -88,8 +89,7 @@ class SqueakNode:
|
|||
def start_running(self):
|
||||
self.squeak_block_periodic_worker.start_running()
|
||||
self.squeak_block_queue_worker.start_running()
|
||||
if self.enable_sync:
|
||||
self.squeak_peer_sync_worker.start_running()
|
||||
self.squeak_peer_sync_worker.start_running()
|
||||
self.squeak_offer_expiry_worker.start_running()
|
||||
|
||||
def save_uploaded_squeak(self, squeak):
|
||||
|
|
|
|||
|
|
@ -4,22 +4,20 @@ import threading
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
SUBSCRIBE_UPDATE_INTERVAL_S = 10.0
|
||||
|
||||
|
||||
class SqueakPeerSyncWorker:
|
||||
def __init__(
|
||||
self,
|
||||
squeak_sync_controller,
|
||||
update_interval_s=SUBSCRIBE_UPDATE_INTERVAL_S,
|
||||
sync_interval_s,
|
||||
):
|
||||
self.squeak_sync_controller = squeak_sync_controller
|
||||
self.update_interval_s = update_interval_s
|
||||
self.sync_interval_s = sync_interval_s
|
||||
|
||||
def sync_timeline(self):
|
||||
logger.info("Syncing timeline with peers...")
|
||||
self.squeak_sync_controller.sync_timeline()
|
||||
|
||||
def start_running(self):
|
||||
threading.Timer(self.update_interval_s, self.start_running).start()
|
||||
self.sync_timeline()
|
||||
if self.sync_interval_s:
|
||||
threading.Timer(self.sync_interval_s, self.start_running).start()
|
||||
self.sync_timeline()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue