Multiple attempts to change role to compensate Zendesk API delay

This commit is contained in:
Iurii Tatishchev 2021-04-20 14:39:27 -07:00
parent 045d2cfb2b
commit a5d0c222bd
Signed by: CaZzzer
GPG Key ID: 926BE949E29DCD03

View File

@ -48,8 +48,8 @@ def make_light_agent(user_profile: UserProfile, who_changes: User) -> None:
:return: Вызов функции **update_role** с параметрами: профиль пользователя, роль "light_agent"
"""
tickets = get_tickets_list(user_profile.user.email)
tickets_to_update = []
buffer_group = zenpy.get_group(ZENDESK_GROUPS['buffer'])
solved_tickets_user = zenpy.get_user(SOLVED_TICKETS_EMAIL)
for ticket in tickets:
UnassignedTicket.objects.create(
assignee=user_profile.user,
@ -57,15 +57,22 @@ def make_light_agent(user_profile: UserProfile, who_changes: User) -> None:
status=UnassignedTicketStatus.SOLVED if ticket.status == 'solved' else UnassignedTicketStatus.UNASSIGNED
)
if ticket.status == 'solved':
ticket.assignee = zenpy.get_user(SOLVED_TICKETS_EMAIL)
ticket.assignee = solved_tickets_user
else:
ticket.assignee = None
ticket.group = buffer_group
tickets_to_update.append(ticket)
print(tickets_to_update)
zenpy.admin.tickets.update(tickets.values)
update_role(user_profile, ROLES['light_agent'])
attempts, success = 5, False
while not success and attempts != 0:
try:
update_role(user_profile, ROLES['light_agent'])
success = True
except APIException as e:
attempts -= 1
if attempts == 0:
raise e
def get_users_list() -> list: