41 lines
1006 B
Python
41 lines
1006 B
Python
#!/usr/bin/env python3
|
|
"""
|
|
Purge old failed messages from NATS JetStream
|
|
"""
|
|
import asyncio
|
|
import nats
|
|
import os
|
|
|
|
async def purge_messages():
|
|
nats_url = "nats://nats.workolik.com:4222"
|
|
nats_user = "admin"
|
|
nats_password = "package@321#"
|
|
|
|
try:
|
|
print(f"Connecting to NATS at {nats_url}...")
|
|
nc = await nats.connect(
|
|
servers=[nats_url],
|
|
user=nats_user,
|
|
password=nats_password
|
|
)
|
|
print("✅ Connected to NATS")
|
|
|
|
js = nc.jetstream()
|
|
|
|
# Purge the stream to remove all old messages
|
|
print("Purging old messages from stream 'EVENTS'...")
|
|
await js.purge_stream("EVENTS")
|
|
print("✅ Stream purged - all old messages removed")
|
|
|
|
await nc.close()
|
|
print("✅ Done!")
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(purge_messages())
|
|
|