diff --git a/main/extra_func.py b/main/extra_func.py index f8d95b8..162adaf 100644 --- a/main/extra_func.py +++ b/main/extra_func.py @@ -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: