Files

20 lines
972 B
Python

"""Trusted operator CLI, no public replay or arbitrary job submission endpoint."""
import argparse
import json
from psycopg.rows import dict_row
from app import store
from pipeline import replay,upgrade
if __name__=='__main__':
p=argparse.ArgumentParser();p.add_argument('action',choices=['failed','replay','upgrade']);p.add_argument('id',nargs='?');args=p.parse_args()
store.pool.open(wait=True,timeout=30)
try:
if args.action=='failed':
with store.connect() as conn:
rows=conn.cursor(row_factory=dict_row).execute("SELECT id,attachment_id,pipeline_version,attempt,error_code,updated_at FROM jobs WHERE state='failed' ORDER BY updated_at LIMIT 100").fetchall()
print(json.dumps(rows,default=str,indent=2))
elif not args.id:p.error('id is required')
elif args.action=='replay':replay(store,args.id);print('requeued')
else:print(upgrade(store,args.id))
finally:store.pool.close()