Skip to content

Commit

Permalink
Fix repitition count (#573)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hrishabh17 authored May 17, 2024
1 parent 0013cf2 commit f378a03
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
18 changes: 8 additions & 10 deletions apps/netsuite/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __handle_netsuite_connection_error(expense_group: ExpenseGroup, task_log: Ta
}

if expense_group:
error, created = Error.objects.update_or_create(
error, _ = Error.objects.update_or_create(
workspace_id=expense_group.workspace_id,
expense_group=expense_group,
defaults={
Expand All @@ -53,7 +53,7 @@ def __handle_netsuite_connection_error(expense_group: ExpenseGroup, task_log: Ta
'is_resolved': False
})

error.increase_repetition_count_by_one(created)
error.increase_repetition_count_by_one()

task_log.status = 'FAILED'
task_log.detail = detail
Expand Down Expand Up @@ -139,7 +139,7 @@ def wrapper(*args):
if parsed_message:
is_parsed = True
all_details[-1]['message'] = parsed_message
error, created = Error.objects.update_or_create(
error, _ = Error.objects.update_or_create(
workspace_id=expense_group.workspace_id,
expense_group=expense_group,
defaults={
Expand All @@ -152,7 +152,7 @@ def wrapper(*args):
}
)

error.increase_repetition_count_by_one(created)
error.increase_repetition_count_by_one()

task_log.detail = all_details

Expand All @@ -172,18 +172,17 @@ def wrapper(*args):

except NetSuiteRateLimitError:
if not payment:
error, created = Error.objects.update_or_create(
error, _ = Error.objects.update_or_create(
workspace_id=expense_group.workspace_id,
expense_group=expense_group,
defaults={
'type': 'NETSUITE_ERROR',
'error_title': netsuite_error_message,
'error_detail': f'Rate limit error, workspace_id - {expense_group.workspace_id}',
'repetition_count': F('repetition_count') + 1,
'is_resolved': False
}
)
error.increase_repetition_count_by_one(created)
error.increase_repetition_count_by_one()

logger.info('Rate limit error, workspace_id - %s', workspace_id if payment else expense_group.workspace_id)
task_log.status = 'FAILED'
Expand All @@ -208,18 +207,17 @@ def wrapper(*args):
task_log.detail = detail
task_log.save()

error, created = Error.objects.update_or_create(
error, _ = Error.objects.update_or_create(
workspace_id=workspace_id,
expense_group=expense_group,
defaults={
'type': 'NETSUITE_ERROR',
'error_title': 'Something unexpected has happened during export',
'error_detail': f'{detail}, workspace_id - {workspace_id}',
'repetition_count': F('repetition_count') + 1,
'is_resolved': False
}
)
error.increase_repetition_count_by_one(created)
error.increase_repetition_count_by_one()

except Exception:
error = traceback.format_exc()
Expand Down
12 changes: 6 additions & 6 deletions apps/netsuite/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ def __validate_tax_group_mapping(expense_group: ExpenseGroup, configuration: Con
})

if tax_group:
error, created = Error.objects.update_or_create(
error, _ = Error.objects.update_or_create(
workspace_id=tax_group.workspace_id,
expense_attribute=tax_group,
defaults={
Expand All @@ -836,7 +836,7 @@ def __validate_tax_group_mapping(expense_group: ExpenseGroup, configuration: Con
}
)

error.increase_repetition_count_by_one(created)
error.increase_repetition_count_by_one()

row = row + 1

Expand Down Expand Up @@ -916,7 +916,7 @@ def __validate_employee_mapping(expense_group: ExpenseGroup, configuration: Conf
})

if employee:
error, created = Error.objects.update_or_create(
error, _ = Error.objects.update_or_create(
workspace_id=expense_group.workspace_id,
expense_attribute=employee,
defaults={
Expand All @@ -926,7 +926,7 @@ def __validate_employee_mapping(expense_group: ExpenseGroup, configuration: Conf
'is_resolved': False
}
)
error.increase_repetition_count_by_one(created)
error.increase_repetition_count_by_one()

return bulk_errors

Expand Down Expand Up @@ -973,7 +973,7 @@ def __validate_category_mapping(expense_group: ExpenseGroup, configuration: Conf
})

if category_attribute:
error, created = Error.objects.update_or_create(
error, _ = Error.objects.update_or_create(
workspace_id=expense_group.workspace_id,
expense_attribute=category_attribute,
defaults={
Expand All @@ -983,7 +983,7 @@ def __validate_category_mapping(expense_group: ExpenseGroup, configuration: Conf
'is_resolved': False
}
)
error.increase_repetition_count_by_one(created)
error.increase_repetition_count_by_one()

row = row + 1

Expand Down
8 changes: 3 additions & 5 deletions apps/tasks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,12 @@ class Error(models.Model):
created_at = models.DateTimeField(auto_now_add=True, help_text='Created at datetime')
updated_at = models.DateTimeField(auto_now=True, help_text='Updated at datetime')


def increase_repetition_count_by_one(self, is_created: bool):
def increase_repetition_count_by_one(self):
"""
Increase the repetition count by 1.
"""
if not is_created:
self.repetition_count += 1
self.save()
self.repetition_count += 1
self.save()

class Meta:
db_table = 'errors'

0 comments on commit f378a03

Please sign in to comment.