[fs2zammad] retry import due to unpredictable 503

This commit is contained in:
fnux 2024-05-02 16:27:50 +02:00
parent 900f8d6a44
commit 807ed89c08
No known key found for this signature in database
GPG key ID: 4502C902C00A1E12

View file

@ -110,7 +110,8 @@ def maybe_create_zammad_user(userdata, zammad_session, attr="login", default=Non
# id, {"roles": roles.append("Agent")}
# )
def create_zammad_ticket(id, zammad, h2t):
def create_zammad_ticket(id, zammad, h2t, retries=3):
try:
with open(f"tickets/{id}", "rb") as handle:
rt_ticket = pickle.load(handle)
@ -237,6 +238,13 @@ def create_zammad_ticket(id, zammad, h2t):
if restore_creator_to != None:
zammad.ticket.update(zammad_ticket["id"], {"customer_id": restore_creator_to})
except KeyboardInterrupt:
print("Received keyboard interrupt. Exiting.")
sys.exit()
except:
print(f"Failed to import RT-#{id} .. ({retries} retries left)")
if retries > 0:
create_zammad_ticket(id, zammad, h2t, retries - 1)
### main logic ###
@ -262,9 +270,8 @@ print(f"Found {len(ticket_ids)} tickets on filesystem.")
for id in ticket_ids:
try:
create_zammad_ticket(id, zammad, h2t)
except KeyboardInterrupt:
print("Received keyboard interrupt. Exiting.")
create_zammad_ticket(id, zammad, h2t, 3)
except SystemExit:
sys.exit()
except:
print(f"Failed to import RT#{id}")