mirror of
https://github.com/discourse/discourse.git
synced 2025-06-07 22:56:01 +08:00
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:
@ -25,8 +25,14 @@ class WebHookEventsDailyAggregate < ActiveRecord::Base
|
|||||||
self.web_hook_id,
|
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.successful_event_count = events.where("status >= 200 AND status <= 299").count
|
||||||
self.failed_event_count = events.where("status < 200 OR status > 299").count
|
self.failed_event_count = events.where("status < 200 OR status > 299").count
|
||||||
end
|
end
|
||||||
|
@ -110,5 +110,11 @@ RSpec.describe WebHookEventsDailyAggregate do
|
|||||||
WebHookEventsDailyAggregate.count
|
WebHookEventsDailyAggregate.count
|
||||||
}
|
}
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user