mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-12-05 05:41:03 +01:00
move reconcile relays to dvmconfig, shutdown client on reconcile
This commit is contained in:
@@ -175,24 +175,23 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
|
||||
return 1
|
||||
|
||||
def sync_db(self):
|
||||
opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT)))
|
||||
opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_LONG_TIMEOUT)))
|
||||
sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY)
|
||||
keys = Keys.parse(sk.to_hex())
|
||||
signer = NostrSigner.keys(keys)
|
||||
database = NostrDatabase.sqlite(self.db_name)
|
||||
cli = ClientBuilder().signer(signer).database(database).opts(opts).build()
|
||||
|
||||
ropts = RelayOptions().ping(True)
|
||||
cli.add_relay_with_opts("wss://relay.damus.io", ropts)
|
||||
cli.add_relay_with_opts("wss://nostr.oxtr.dev", ropts)
|
||||
cli.add_relay_with_opts("wss://nostr21.com", ropts)
|
||||
for relay in self.dvm_config.RECONCILE_DB_RELAY_LIST:
|
||||
cli.add_relay(relay)
|
||||
|
||||
cli.connect()
|
||||
|
||||
timestamp_hour_ago = Timestamp.now().as_secs() - self.db_since
|
||||
lasthour = Timestamp.from_secs(timestamp_hour_ago)
|
||||
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(lasthour) # Notes, reactions, zaps
|
||||
definitions.EventDefinitions.KIND_ZAP]).since(since) # Notes, reactions, zaps
|
||||
|
||||
# filter = Filter().author(keys.public_key())
|
||||
print("[" + self.dvm_config.IDENTIFIER + "] Syncing notes of the last " + str(
|
||||
@@ -200,8 +199,8 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
|
||||
dbopts = NegentropyOptions().direction(NegentropyDirection.DOWN)
|
||||
cli.reconcile(filter1, dbopts)
|
||||
database.delete(Filter().until(Timestamp.from_secs(
|
||||
Timestamp.now().as_secs() - self.db_since))) # Clear old events so db doesnt get too full.
|
||||
|
||||
Timestamp.now().as_secs() - self.db_since))) # Clear old events so db doesn't get too full.
|
||||
cli.shutdown()
|
||||
print(
|
||||
"[" + self.dvm_config.IDENTIFIER + "] Done Syncing Notes of the last " + str(self.db_since) + " seconds..")
|
||||
|
||||
|
||||
@@ -193,23 +193,34 @@ class DicoverContentCurrentlyPopularZaps(DVMTaskInterface):
|
||||
return 1
|
||||
|
||||
def sync_db(self):
|
||||
opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_LONG_TIMEOUT)))
|
||||
sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY)
|
||||
keys = Keys.parse(sk.to_hex())
|
||||
signer = NostrSigner.keys(keys)
|
||||
database = NostrDatabase.sqlite(self.db_name)
|
||||
cli = ClientBuilder().signer(signer).database(database).opts(opts).build()
|
||||
|
||||
timestamp_hour_ago = Timestamp.now().as_secs() - self.db_since
|
||||
lasthour = Timestamp.from_secs(timestamp_hour_ago)
|
||||
for relay in self.dvm_config.RECONCILE_DB_RELAY_LIST:
|
||||
cli.add_relay(relay)
|
||||
|
||||
cli.connect()
|
||||
|
||||
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(lasthour) # Notes, reactions, zaps
|
||||
definitions.EventDefinitions.KIND_ZAP]).since(since) # Notes, reactions, zaps
|
||||
|
||||
# filter = Filter().author(keys.public_key())
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] Syncing notes of the last " + str(
|
||||
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)
|
||||
self.client.reconcile(filter1, dbopts)
|
||||
filter_delete = Filter().until(Timestamp.from_secs(Timestamp.now().as_secs() - self.db_since))
|
||||
self.client.database().delete(filter_delete) # Clear old events so db doesn't get too full.
|
||||
|
||||
cli.reconcile(filter1, dbopts)
|
||||
database.delete(Filter().until(Timestamp.from_secs(
|
||||
Timestamp.now().as_secs() - self.db_since))) # Clear old events so db doesn't get too full.
|
||||
cli.shutdown()
|
||||
print(
|
||||
"[" + self.dvm_config.NIP89.NAME + "] Done Syncing Notes of the last " + str(self.db_since) + " seconds..")
|
||||
"[" + self.dvm_config.IDENTIFIER + "] Done Syncing Notes of the last " + str(self.db_since) + " seconds..")
|
||||
|
||||
|
||||
# We build an example here that we can call by either calling this file directly from the main directory,
|
||||
|
||||
@@ -190,31 +190,37 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
||||
self.last_schedule = Timestamp.now().as_secs()
|
||||
return 1
|
||||
|
||||
|
||||
def sync_db(self):
|
||||
opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT)))
|
||||
opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_LONG_TIMEOUT)))
|
||||
sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY)
|
||||
keys = Keys.parse(sk.to_hex())
|
||||
signer = NostrSigner.keys(keys)
|
||||
database = NostrDatabase.sqlite(self.db_name)
|
||||
cli = ClientBuilder().signer(signer).database(database).opts(opts).build()
|
||||
|
||||
cli.add_relay("wss://relay.damus.io")
|
||||
for relay in self.dvm_config.RECONCILE_DB_RELAY_LIST:
|
||||
cli.add_relay(relay)
|
||||
|
||||
cli.connect()
|
||||
|
||||
timestamp_hour_ago = Timestamp.now().as_secs() - self.db_since
|
||||
lasthour = Timestamp.from_secs(timestamp_hour_ago)
|
||||
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(lasthour) # Notes, reactions, zaps
|
||||
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())
|
||||
print("[" + self.dvm_config.IDENTIFIER + "] Syncing notes of the last " + str(self.db_since) + " seconds.. this might take a while..")
|
||||
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)
|
||||
cli.reconcile(filter1, dbopts)
|
||||
database.delete(Filter().until(Timestamp.from_secs(
|
||||
Timestamp.now().as_secs() - self.db_since))) # Clear old events so db doesnt get too full.
|
||||
|
||||
print("[" + self.dvm_config.IDENTIFIER + "] Done Syncing Notes of the last " + str(self.db_since) + " seconds..")
|
||||
Timestamp.now().as_secs() - self.db_since))) # Clear old events so db doesn't get too full.
|
||||
cli.shutdown()
|
||||
print("[" + self.dvm_config.IDENTIFIER + "] Done Syncing Notes of the last " + str(
|
||||
self.db_since) + " seconds..")
|
||||
|
||||
|
||||
# We build an example here that we can call by either calling this file directly from the main directory,
|
||||
|
||||
@@ -196,24 +196,16 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
||||
return 1
|
||||
|
||||
def sync_db(self):
|
||||
opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT)))
|
||||
opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_LONG_TIMEOUT)))
|
||||
sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY)
|
||||
keys = Keys.parse(sk.to_hex())
|
||||
signer = NostrSigner.keys(keys)
|
||||
database = NostrDatabase.sqlite(self.db_name)
|
||||
cli = ClientBuilder().signer(signer).database(database).opts(opts).build()
|
||||
|
||||
cli.add_relay("wss://relay.damus.io")
|
||||
cli.add_relay("wss://nostr.oxtr.dev")
|
||||
cli.add_relay("wss://relay.nostr.net")
|
||||
cli.add_relay("wss://relay.nostr.bg")
|
||||
cli.add_relay("wss://nostr.wine")
|
||||
cli.add_relay("wss://nostr21.com")
|
||||
for relay in self.dvm_config.RECONCILE_DB_RELAY_LIST:
|
||||
cli.add_relay(relay)
|
||||
|
||||
#RELAY_LIST = [ "wss://nostr.wine",
|
||||
# , "wss://relay.nostr.bg",
|
||||
# , "wss://relay.nostr.net"
|
||||
# ]
|
||||
cli.connect()
|
||||
|
||||
timestamp_since = Timestamp.now().as_secs() - self.db_since
|
||||
@@ -227,7 +219,7 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
||||
cli.reconcile(filter1, dbopts)
|
||||
database.delete(Filter().until(Timestamp.from_secs(
|
||||
Timestamp.now().as_secs() - self.db_since))) # Clear old events so db doesn't get too full.
|
||||
|
||||
cli.shutdown()
|
||||
print("[" + self.dvm_config.IDENTIFIER + "] Done Syncing Notes of the last " + str(self.db_since) + " seconds..")
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,13 @@ class DVMConfig:
|
||||
"wss://relay.nostr.net"
|
||||
]
|
||||
|
||||
RECONCILE_DB_RELAY_LIST = ["wss://relay.damus.io", "wss://nostr21.com",
|
||||
"wss://nostr.oxtr.dev", "wss://relay.nostr.bg",
|
||||
"wss://relay.nostr.net" , "wss://relay.primal.net"] #, "wss://relay.snort.social"]
|
||||
|
||||
|
||||
# cli.add_relay("wss://relay.primal.net")
|
||||
|
||||
#"wss://relay.damus.io"
|
||||
|
||||
RELAY_TIMEOUT = 5
|
||||
|
||||
2
setup.py
2
setup.py
@@ -1,6 +1,6 @@
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
VERSION = '0.5.6'
|
||||
VERSION = '0.5.7'
|
||||
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')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user