Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add success percentage on outgoing webhooks endpoint table #255

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,12 @@ def event_types
def touch_parent
send(BulletTrain::OutgoingWebhooks.parent_association).touch
end

def error_rate_percentage
total = deliveries.where(created_at: 30.days.ago..Time.now).count
failed = deliveries.where(created_at: 30.days.ago..Time.now).where(delivered_at: nil).count

return 0 if total == 0 || failed == 0
error_percentage = (failed.to_f / total.to_f) * 100
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<tr>
<th><%= t('.fields.name.heading') %></th>
<th><%= t('.fields.url.heading') %></th>
<th><%= t('.fields.error_rate.heading') %></th>
<%# 🚅 super scaffolding will insert new field headers above this line. %>
<th class="text-right"></th>
</tr>
Expand All @@ -25,6 +26,7 @@
<tr data-id="<%= endpoint.id %>">
<td><%= render 'shared/attributes/text', attribute: :name, url: [:account, endpoint] %></td>
<td><%= render 'shared/attributes/code', attribute: :url %></td>
<td><%= render 'account/shared/capsule_label', value: number_to_percentage(endpoint.error_rate_percentage, precision: 1) %></td>
<%# 🚅 super scaffolding will insert new fields above this line. %>
<td class="buttons">
<% unless hide_actions %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ en:
label: *url
heading: *url

error_rate:
_: &error_rate ERROR RATE
label: *error_rate
heading: *error_rate

api_version:
_: &api_version API Version
label: *api_version
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% value ||= "0.0%" %>

<%
if value == "0.0%"
label_classes = "bg-green-200 text-green-600"
else
label_classes = "bg-red-200 text-red-900"
end
%>

<span class="<%= label_classes %> p-1 rounded-xl"><%= value %></span>