20 lines
1.1 KiB
Python
20 lines
1.1 KiB
Python
"""Inspect local backlog, or quarantine a known invalid event without losing it."""
|
|
import argparse,json,os
|
|
from .outbox import Outbox
|
|
|
|
def main():
|
|
p=argparse.ArgumentParser();p.add_argument('path');p.add_argument('--quarantine-id');p.add_argument('--reason',default='operator review');args=p.parse_args()
|
|
os.umask(0o077);out=Outbox(args.path)
|
|
if args.quarantine_id:
|
|
with out.lock,out.db:
|
|
out.db.execute('CREATE TABLE IF NOT EXISTS quarantine(id TEXT PRIMARY KEY, body TEXT NOT NULL, reason TEXT NOT NULL)')
|
|
row=out.db.execute('SELECT id,body FROM outbox WHERE id=?',(args.quarantine_id,)).fetchone()
|
|
if not row:raise SystemExit('Event ID not found')
|
|
out.db.execute('INSERT OR REPLACE INTO quarantine VALUES (?,?,?)',(*row,args.reason))
|
|
out.db.execute('DELETE FROM outbox WHERE id=?',(args.quarantine_id,))
|
|
print('Event retained in quarantine table; other events can be transmitted.')
|
|
else:
|
|
print(json.dumps({'pending':out.count(),'first_events':[e for _,e in out.batch(5)]},indent=2))
|
|
out.close()
|
|
if __name__=='__main__':main()
|