FIX: Division by zero error on WebHookEventsDailyAggregate (#27667)
* FIX: Division by zero error on WebHookEventsDailyAggregate * DEV: Update implementation of WebHookEventsDailyAggregate to handle division by zero error
This commit is contained in:
parent
88d259b73a
commit
1ae902fa60
|
@ -25,8 +25,14 @@ class WebHookEventsDailyAggregate < ActiveRecord::Base
|
|||
self.web_hook_id,
|
||||
)
|
||||
|
||||
self.mean_duration = events.sum(:duration) / events.count
|
||||
if events.empty?
|
||||
self.mean_duration = 0
|
||||
self.successful_event_count = 0
|
||||
self.failed_event_count = 0
|
||||
return
|
||||
end
|
||||
|
||||
self.mean_duration = events.sum(:duration) / events.count
|
||||
self.successful_event_count = events.where("status >= 200 AND status <= 299").count
|
||||
self.failed_event_count = events.where("status < 200 OR status > 299").count
|
||||
end
|
||||
|
|
|
@ -110,5 +110,11 @@ RSpec.describe WebHookEventsDailyAggregate do
|
|||
WebHookEventsDailyAggregate.count
|
||||
}
|
||||
end
|
||||
|
||||
it "should not fail if there are no events" do
|
||||
expect { Jobs::AggregateWebHooksEvents.new.execute(date: 99.days.ago) }.not_to raise_error
|
||||
|
||||
expect(WebHookEventsDailyAggregate.count).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue