feat: wire Nostr subscription sync into extension lifecycle
Add background task that subscribes to kind 31922/31923 events from relays and processes them into the local database. Starts 15s after NostrClient connects (sequenced after publish client). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
e937883564
commit
ef5d2dcfcf
1 changed files with 20 additions and 2 deletions
22
__init__.py
22
__init__.py
|
|
@ -50,14 +50,32 @@ def events_start():
|
||||||
from .nostr.nostr_client import NostrClient
|
from .nostr.nostr_client import NostrClient
|
||||||
|
|
||||||
nostr_client = NostrClient()
|
nostr_client = NostrClient()
|
||||||
logger.info("[EVENTS] Starting NostrClient for NIP-52 publishing")
|
logger.info("[EVENTS] Starting NostrClient for NIP-52 sync")
|
||||||
await nostr_client.run_forever()
|
await nostr_client.run_forever()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"[EVENTS] NostrClient failed to start: {e}")
|
logger.warning(f"[EVENTS] NostrClient failed to start: {e}")
|
||||||
logger.info("[EVENTS] Events will work without Nostr publishing")
|
logger.info("[EVENTS] Events will work without Nostr sync")
|
||||||
|
|
||||||
task2 = create_permanent_unique_task("ext_events_nostr", _start_nostr_client)
|
task2 = create_permanent_unique_task("ext_events_nostr", _start_nostr_client)
|
||||||
scheduled_tasks.append(task2)
|
scheduled_tasks.append(task2)
|
||||||
|
|
||||||
|
async def _sync_nostr_events():
|
||||||
|
global nostr_client
|
||||||
|
await asyncio.sleep(15) # Wait for NostrClient to connect
|
||||||
|
if not nostr_client:
|
||||||
|
logger.info("[EVENTS] No NostrClient, skipping Nostr sync")
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
from .nostr_sync import wait_for_nostr_events
|
||||||
|
|
||||||
|
await wait_for_nostr_events(nostr_client)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"[EVENTS] Nostr sync task failed: {e}")
|
||||||
|
|
||||||
|
task3 = create_permanent_unique_task(
|
||||||
|
"ext_events_nostr_sync", _sync_nostr_events
|
||||||
|
)
|
||||||
|
scheduled_tasks.append(task3)
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["db", "events_ext", "events_start", "events_static_files", "events_stop"]
|
__all__ = ["db", "events_ext", "events_start", "events_static_files", "events_stop"]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue