Skip to content

Commit

Permalink
feat: adding a notification limit
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0elliot committed Mar 24, 2024
1 parent db24d91 commit 60bc85a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions backend/api_app/monitoring/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,16 @@ def trace_transaction(transaction_hash):
continue

for alert in alerts:
notifications = Notification.objects.filter(
alert__smart_contract__owner_organization=monitoring_task.SmartContract.owner_organization,
).count()

if notifications >= monitoring_task.SmartContract.owner_organization.notification_limit:
logger.info(
f"[DEBUG] Notification limit reached for organization {monitoring_task.SmartContract.owner_organization}"
)
return # we don't want to run more alerts

logger.info(f"[DEBUG] Running alert {alert.id}")
alert_runner = BlockchainAlertRunner(alert, transaction)
alert_runner.run()
Expand Down
1 change: 1 addition & 0 deletions backend/authentication/organizations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def invite_user_from_email(email, invited_by, organization=None, token=None):
class Organization(BaseMixin):
id = models.UUIDField(primary_key=True, editable=False)
name = models.CharField(max_length=100)
notification_limit = models.PositiveIntegerField(default=5)

class Meta:
verbose_name = _("Organization")
Expand Down

0 comments on commit 60bc85a

Please sign in to comment.