Initial commit
This commit is contained in:
40
scripts/purge-old-messages.py
Normal file
40
scripts/purge-old-messages.py
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/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())
|
||||
|
||||
Reference in New Issue
Block a user