diff --git a/nostr_dvm/tasks/content_discovery_update_db_only.py b/nostr_dvm/tasks/content_discovery_update_db_only.py index 3045831..2624f70 100644 --- a/nostr_dvm/tasks/content_discovery_update_db_only.py +++ b/nostr_dvm/tasks/content_discovery_update_db_only.py @@ -122,38 +122,40 @@ class DicoverContentDBUpdateScheduler(DVMTaskInterface): return 1 async def sync_db(self): - relaylimits = RelayLimits.disable() - opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_LONG_TIMEOUT))).relay_limits(relaylimits) - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) - keys = Keys.parse(sk.to_hex()) - signer = NostrSigner.keys(keys) - database = await NostrDatabase.sqlite(self.db_name) - cli = ClientBuilder().signer(signer).database(database).opts(opts).build() + try: + relaylimits = RelayLimits.disable() + opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_LONG_TIMEOUT))).relay_limits(relaylimits) + sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + keys = Keys.parse(sk.to_hex()) + signer = NostrSigner.keys(keys) + database = await NostrDatabase.sqlite(self.db_name) + cli = ClientBuilder().signer(signer).database(database).opts(opts).build() - for relay in self.dvm_config.RECONCILE_DB_RELAY_LIST: - await cli.add_relay(relay) + for relay in self.dvm_config.RECONCILE_DB_RELAY_LIST: + await cli.add_relay(relay) - await cli.connect() + await cli.connect() - timestamp_since = Timestamp.now().as_secs() - self.db_since - since = Timestamp.from_secs(timestamp_since) + timestamp_since = Timestamp.now().as_secs() - self.db_since + since = Timestamp.from_secs(timestamp_since) - filter1 = Filter().kinds([definitions.EventDefinitions.KIND_NOTE, definitions.EventDefinitions.KIND_REACTION, - definitions.EventDefinitions.KIND_ZAP]).since(since) # Notes, reactions, zaps - - # filter = Filter().author(keys.public_key()) - if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value: - print("[" + self.dvm_config.IDENTIFIER + "] Syncing notes of the last " + str( - self.db_since) + " seconds.. this might take a while..") - dbopts = NegentropyOptions().direction(NegentropyDirection.DOWN) - await cli.reconcile(filter1, dbopts) - await cli.database().delete(Filter().until(Timestamp.from_secs( - Timestamp.now().as_secs() - self.db_since))) # Clear old events so db doesn't get too full. - await cli.shutdown() - if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value: - print( - "[" + self.dvm_config.IDENTIFIER + "] Done Syncing Notes of the last " + str(self.db_since) + " seconds..") + filter1 = Filter().kinds([definitions.EventDefinitions.KIND_NOTE, definitions.EventDefinitions.KIND_REACTION, + definitions.EventDefinitions.KIND_ZAP]).since(since) # Notes, reactions, zaps + # filter = Filter().author(keys.public_key()) + if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value: + print("[" + self.dvm_config.IDENTIFIER + "] Syncing notes of the last " + str( + self.db_since) + " seconds.. this might take a while..") + dbopts = NegentropyOptions().direction(NegentropyDirection.DOWN) + await cli.reconcile(filter1, dbopts) + await cli.database().delete(Filter().until(Timestamp.from_secs( + Timestamp.now().as_secs() - self.db_since))) # Clear old events so db doesn't get too full. + await cli.shutdown() + if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value: + print( + "[" + self.dvm_config.IDENTIFIER + "] Done Syncing Notes of the last " + str(self.db_since) + " seconds..") + except Exception as e: + print(e) # We build an example here that we can call by either calling this file directly from the main directory, # or by adding it to our playground. You can call the example and adjust it to your needs or redefine it in the diff --git a/setup.py b/setup.py index bfb4c9c..be3e9f7 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -VERSION = '0.8.5' +VERSION = '0.8.6' DESCRIPTION = 'A framework to build and run Nostr NIP90 Data Vending Machines' LONG_DESCRIPTION = ('A framework to build and run Nostr NIP90 Data Vending Machines. See the github repository for more information')