From 90e959270f3485031380ac8131ae716d1839dd89 Mon Sep 17 00:00:00 2001 From: dbth <1097224+believethehype@users.noreply.github.com> Date: Sat, 4 Jan 2025 19:13:22 +0100 Subject: [PATCH] handle exception, adapt more tests to framework --- .gitignore | 1 + nostr_dvm/utils/nostr_utils.py | 11 +++++++++-- tests/discovery_mostr.py | 8 ++++++-- tests/generic_dvm_duck_chat.py | 5 ++++- tests/generic_dvm_flux_hf.py | 5 ++++- tests/otherstuff.py | 2 +- 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index bc4c977..65d219a 100644 --- a/.gitignore +++ b/.gitignore @@ -198,3 +198,4 @@ tests/cat4.png *.png tests/gifs/data.mdb tests/gifs/lock.mdb +tests/gif_library.py diff --git a/nostr_dvm/utils/nostr_utils.py b/nostr_dvm/utils/nostr_utils.py index 70f260d..6df0228 100644 --- a/nostr_dvm/utils/nostr_utils.py +++ b/nostr_dvm/utils/nostr_utils.py @@ -237,7 +237,10 @@ async def send_event_outbox(event: Event, client, dvm_config) -> SendEventOutput if len(relays) == 0: return None for relay in relays: - await outboxclient.add_relay(relay) + try: + await outboxclient.add_relay(relay) + except: + print("[" + dvm_config.NIP89.NAME + "] " + relay + " couldn't be added to outbox relays") try: await outboxclient.connect() event_response = await outboxclient.send_event(event) @@ -276,7 +279,11 @@ async def send_event(event: Event, client: Client, dvm_config, broadcast=False): for relay in relays: if relay not in dvm_config.RELAY_LIST: - await client.add_relay(relay) + try: + await client.add_relay(relay) + except: + print("[" + dvm_config.NIP89.NAME + "] " + relay + " couldn't be added to relays") + await client.connect() diff --git a/tests/discovery_mostr.py b/tests/discovery_mostr.py index 6d1343d..a0302bd 100644 --- a/tests/discovery_mostr.py +++ b/tests/discovery_mostr.py @@ -4,6 +4,7 @@ from pathlib import Path import dotenv from nostr_sdk import init_logger, LogLevel +from nostr_dvm.framework import DVMFramework from nostr_dvm.tasks.content_discovery_currently_popular_mostr import DicoverContentCurrentlyPopularMostr from nostr_dvm.utils.admin_utils import AdminConfig from nostr_dvm.utils.dvmconfig import build_default_config @@ -23,7 +24,7 @@ if use_logger: init_logger(LogLevel.ERROR) -RELAY_LIST = ["wss://nostr.mom", +RELAY_LIST = ["wss://relay.nostrdvm.com", #"wss://relay.primal.net", "wss://nostr.oxtr.dev", #"wss://relay.nostr.net" @@ -72,6 +73,8 @@ def build_example_mostr(name, identifier, admin_config, options, image, cost=0, def playground(): + + framework = DVMFramework() # Popular Global admin_config_global_wot = AdminConfig() admin_config_global_wot.REBROADCAST_NIP89 = rebroadcast_NIP89 @@ -101,7 +104,8 @@ def playground(): update_rate=global_update_rate, processing_msg=custom_processing_msg, update_db=update_db) - discovery_mostr.run(True) + framework.add(discovery_mostr) + framework.run() diff --git a/tests/generic_dvm_duck_chat.py b/tests/generic_dvm_duck_chat.py index dbb4c13..52bd4e4 100644 --- a/tests/generic_dvm_duck_chat.py +++ b/tests/generic_dvm_duck_chat.py @@ -5,6 +5,7 @@ import dotenv from duck_chat import ModelType from nostr_sdk import Kind +from nostr_dvm.framework import DVMFramework from nostr_dvm.tasks.generic_dvm import GenericDVM from nostr_dvm.utils.admin_utils import AdminConfig from nostr_dvm.utils.dvmconfig import build_default_config @@ -25,6 +26,7 @@ SYNC_DB_RELAY_LIST = ["wss://relay.damus.io", def playground(announce=False): + framework = DVMFramework() kind = 5050 admin_config = AdminConfig() admin_config.REBROADCAST_NIP89 = announce @@ -77,7 +79,8 @@ def playground(announce=False): return result dvm.process = process # overwrite the process function with the above one - dvm.run(True) + framework.add(dvm) + framework.run() if __name__ == '__main__': diff --git a/tests/generic_dvm_flux_hf.py b/tests/generic_dvm_flux_hf.py index 2b79f16..ac047b9 100644 --- a/tests/generic_dvm_flux_hf.py +++ b/tests/generic_dvm_flux_hf.py @@ -5,6 +5,7 @@ from pathlib import Path import dotenv from nostr_sdk import Kind +from nostr_dvm.framework import DVMFramework from nostr_dvm.tasks.generic_dvm import GenericDVM from nostr_dvm.utils.admin_utils import AdminConfig from nostr_dvm.utils.dvmconfig import build_default_config @@ -26,6 +27,7 @@ SYNC_DB_RELAY_LIST = ["wss://relay.damus.io", def playground(announce=False): + framework = DVMFramework() kind = Kind(5100) model = "dev" #schnell @@ -103,7 +105,8 @@ def playground(announce=False): dvm.process = process # overwrite the process function with the above one - dvm.run(True) + framework.add(dvm) + framework.run() if __name__ == '__main__': diff --git a/tests/otherstuff.py b/tests/otherstuff.py index cc8e03c..48c88cb 100644 --- a/tests/otherstuff.py +++ b/tests/otherstuff.py @@ -34,7 +34,7 @@ SYNC_DB_RELAY_LIST = ["wss://relay.damus.io", #"wss://relay.primal.net", "wss://nostr.oxtr.dev"] -RELAY_LIST = ["wss://nostr.mom", +RELAY_LIST = ["wss://relay.nostrdvm.com", #"wss://relay.primal.net", "wss://nostr.oxtr.dev", #"wss://relay.nostr.net"