[rt2fs] retry on failed ticket dump

This commit is contained in:
fnux 2024-04-22 11:52:28 +02:00
parent fb7c1f7582
commit fd401545ca
No known key found for this signature in database
GPG key ID: 4502C902C00A1E12

57
rt2fs
View file

@ -52,34 +52,39 @@ os.makedirs("attachments", exist_ok=True)
ticket_ids = range(config["rt_start"], config["rt_end"]) ticket_ids = range(config["rt_start"], config["rt_end"])
def dump(id): def dump(id, retries=3):
print(f"Dumping RT#{id}") print(f"Dumping RT#{id}")
ticket_dumpfile = f"tickets/{id}" try:
if not os.path.exists(ticket_dumpfile): ticket_dumpfile = f"tickets/{id}"
ticket = rt.get_ticket(id) if not os.path.exists(ticket_dumpfile):
if ticket is None: ticket = rt.get_ticket(id)
print("Got 'None' while fetching ticket") if ticket is None:
os.exit(1) print("Got 'None' while fetching ticket")
ticket["original_id"] = str(id) os.exit(1)
if ticket["Queue"] != 'spam': ticket["original_id"] = str(id)
maybe_dump_user(rt, ticket["Creator"]) if ticket["Queue"] != 'spam':
maybe_dump_user(rt, ticket["Owner"]) maybe_dump_user(rt, ticket["Creator"])
maybe_dump_user(rt, ticket["Owner"])
if ticket["original_id"] != ticket["numerical_id"]: if ticket["original_id"] != ticket["numerical_id"]:
# Merged ticket # Merged ticket
history = [] history = []
else: else:
history = rt.get_history(id) history = rt.get_history(id)
for item in history: for item in history:
for a, title in item["Attachments"]: for a, title in item["Attachments"]:
attachment = rt.get_attachment(id, a) attachment = rt.get_attachment(id, a)
os.makedirs(f"attachments/{id}", exist_ok=True) os.makedirs(f"attachments/{id}", exist_ok=True)
with open(f"attachments/{id}/{a}", "wb") as handle: with open(f"attachments/{id}/{a}", "wb") as handle:
pickle.dump(attachment, handle) pickle.dump(attachment, handle)
maybe_dump_user(rt, item["Creator"]) maybe_dump_user(rt, item["Creator"])
data = {"ticket": ticket, "history": history} data = {"ticket": ticket, "history": history}
with open(ticket_dumpfile, "wb") as handle: with open(ticket_dumpfile, "wb") as handle:
pickle.dump(data, handle) pickle.dump(data, handle)
except:
print(f"Failed to dump RT#{id}.. ({retries} retries left)")
if retries > 0:
dump(id, retries - 1)
worker_count = 4 worker_count = 4
with Pool(worker_count) as p: with Pool(worker_count) as p: