Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions django-backend/soroscan/ingest/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,13 @@ class WebhookSubscriptionAdmin(AdminAuditMixin, admin.ModelAdmin):
"is_active_display",
"timeout_seconds",
"failure_count",
"success_count",
"total_failure_count",
"last_delivery_status",
]
list_filter = ["is_active", "status", "contract", "created_at", "retry_backoff_strategy"]
search_fields = ["target_url", "contract__name", "event_type"]
readonly_fields = ["secret", "created_at", "last_triggered", "failure_count", "status"]
readonly_fields = ["secret", "created_at", "last_triggered", "failure_count", "success_count", "total_failure_count", "status"]
fieldsets = (
(None, {
"fields": ("contract", "target_url", "event_type", "is_active"),
Expand All @@ -532,7 +534,7 @@ class WebhookSubscriptionAdmin(AdminAuditMixin, admin.ModelAdmin):
"Exponential: base * 2^attempt | Linear: base * attempt | Fixed: base",
}),
("Status", {
"fields": ("status", "failure_count", "last_triggered"),
"fields": ("status", "failure_count", "success_count", "total_failure_count", "last_triggered"),
"classes": ("collapse",),
}),
("Secret", {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 5.2.10 on 2026-04-28 15:55

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('ingest', '0038_dependencyimpactassessment_organizationbudget_and_more'),
]

operations = [
migrations.AddField(
model_name='webhooksubscription',
name='success_count',
field=models.PositiveIntegerField(default=0, help_text='Total successful delivery attempts'),
),
migrations.AddField(
model_name='webhooksubscription',
name='total_failure_count',
field=models.PositiveIntegerField(default=0, help_text='Total failed delivery attempts'),
),
migrations.AlterField(
model_name='webhooksubscription',
name='failure_count',
field=models.PositiveIntegerField(default=0, help_text='Consecutive failures since last success'),
),
]
4 changes: 3 additions & 1 deletion django-backend/soroscan/ingest/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,9 @@ class WebhookSubscription(models.Model):
)
created_at = models.DateTimeField(auto_now_add=True)
last_triggered = models.DateTimeField(null=True, blank=True)
failure_count = models.PositiveIntegerField(default=0)
failure_count = models.PositiveIntegerField(default=0, help_text="Consecutive failures since last success")
success_count = models.PositiveIntegerField(default=0, help_text="Total successful delivery attempts")
total_failure_count = models.PositiveIntegerField(default=0, help_text="Total failed delivery attempts")
timeout_seconds = models.IntegerField(
default=10,
validators=[MinValueValidator(1), MaxValueValidator(60)],
Expand Down
12 changes: 11 additions & 1 deletion django-backend/soroscan/ingest/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,18 @@ class Meta:
"created_at",
"last_triggered",
"failure_count",
"success_count",
"total_failure_count",
]
read_only_fields = [
"id",
"contract_id",
"created_at",
"last_triggered",
"failure_count",
"success_count",
"total_failure_count",
]
read_only_fields = ["id", "contract_id", "created_at", "last_triggered", "failure_count"]
extra_kwargs = {
"secret": {"write_only": True},
}
Expand Down
2 changes: 2 additions & 0 deletions django-backend/soroscan/ingest/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ def dispatch_webhook(self, subscription_id: int, event_id: int) -> bool:
if success:
WebhookSubscription.objects.filter(pk=webhook.pk).update(
failure_count=0,
success_count=F("success_count") + 1,
last_triggered=timezone.now(),
)
logger.info(
Expand Down Expand Up @@ -1365,6 +1366,7 @@ def _on_delivery_failure(
"""
WebhookSubscription.objects.filter(pk=webhook.pk).update(
failure_count=F("failure_count") + 1,
total_failure_count=F("total_failure_count") + 1,
)
webhook.refresh_from_db(fields=["failure_count", "status", "is_active", "escalation_policy"])

Expand Down
Loading