Class: GeoMonitor::Status
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- GeoMonitor::Status
- Defined in:
- app/models/geo_monitor/status.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#limit_by_layer ⇒ Object
Limits the number of statuses per layer to prevent a ballooing database.
Class Method Details
.from_response(response, layer, time) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'app/models/geo_monitor/status.rb', line 21 def self.from_response(response, layer, time) create( res_time: time.to_f, res_code: response.status, submitted_query: response.env[:url].to_s, layer: layer, res_headers: response.headers, content_type: response.headers.try(:[], :content_type) ) end |
Instance Method Details
#limit_by_layer ⇒ Object
Limits the number of statuses per layer to prevent a ballooing database
8 9 10 11 12 13 14 15 |
# File 'app/models/geo_monitor/status.rb', line 8 def limit_by_layer statuses_by_layer = self.class.where(layer: layer).count max = ::GeoMonitor::Engine.config.max_status_per_layer self.class .where(layer: layer) .first(statuses_by_layer - max + 1) .map(&:destroy) if statuses_by_layer >= max end |