[rt2fs] retry on failed ticket dump
This commit is contained in:
parent
fb7c1f7582
commit
fd401545ca
1 changed files with 31 additions and 26 deletions
57
rt2fs
57
rt2fs
|
@ -52,34 +52,39 @@ os.makedirs("attachments", exist_ok=True)
|
|||
|
||||
ticket_ids = range(config["rt_start"], config["rt_end"])
|
||||
|
||||
def dump(id):
|
||||
def dump(id, retries=3):
|
||||
print(f"Dumping RT#{id}")
|
||||
ticket_dumpfile = f"tickets/{id}"
|
||||
if not os.path.exists(ticket_dumpfile):
|
||||
ticket = rt.get_ticket(id)
|
||||
if ticket is None:
|
||||
print("Got 'None' while fetching ticket")
|
||||
os.exit(1)
|
||||
ticket["original_id"] = str(id)
|
||||
if ticket["Queue"] != 'spam':
|
||||
maybe_dump_user(rt, ticket["Creator"])
|
||||
maybe_dump_user(rt, ticket["Owner"])
|
||||
try:
|
||||
ticket_dumpfile = f"tickets/{id}"
|
||||
if not os.path.exists(ticket_dumpfile):
|
||||
ticket = rt.get_ticket(id)
|
||||
if ticket is None:
|
||||
print("Got 'None' while fetching ticket")
|
||||
os.exit(1)
|
||||
ticket["original_id"] = str(id)
|
||||
if ticket["Queue"] != 'spam':
|
||||
maybe_dump_user(rt, ticket["Creator"])
|
||||
maybe_dump_user(rt, ticket["Owner"])
|
||||
|
||||
if ticket["original_id"] != ticket["numerical_id"]:
|
||||
# Merged ticket
|
||||
history = []
|
||||
else:
|
||||
history = rt.get_history(id)
|
||||
for item in history:
|
||||
for a, title in item["Attachments"]:
|
||||
attachment = rt.get_attachment(id, a)
|
||||
os.makedirs(f"attachments/{id}", exist_ok=True)
|
||||
with open(f"attachments/{id}/{a}", "wb") as handle:
|
||||
pickle.dump(attachment, handle)
|
||||
maybe_dump_user(rt, item["Creator"])
|
||||
data = {"ticket": ticket, "history": history}
|
||||
with open(ticket_dumpfile, "wb") as handle:
|
||||
pickle.dump(data, handle)
|
||||
if ticket["original_id"] != ticket["numerical_id"]:
|
||||
# Merged ticket
|
||||
history = []
|
||||
else:
|
||||
history = rt.get_history(id)
|
||||
for item in history:
|
||||
for a, title in item["Attachments"]:
|
||||
attachment = rt.get_attachment(id, a)
|
||||
os.makedirs(f"attachments/{id}", exist_ok=True)
|
||||
with open(f"attachments/{id}/{a}", "wb") as handle:
|
||||
pickle.dump(attachment, handle)
|
||||
maybe_dump_user(rt, item["Creator"])
|
||||
data = {"ticket": ticket, "history": history}
|
||||
with open(ticket_dumpfile, "wb") as 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
|
||||
with Pool(worker_count) as p:
|
||||
|
|
Loading…
Reference in a new issue