Skip to content

Commit

Permalink
changed scopes for status page. #233
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jan 19, 2015
1 parent e4baf7e commit 3546579
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions app/models/alert.rb
Expand Up @@ -9,12 +9,12 @@ class Alert < ActiveRecord::Base

default_scope { where("unresolved = ?", true).order("alerts.created_at DESC") }

scope :errors, -> { where("alerts.level > ?", 0) }
scope :errors, -> { where("alerts.level > ?", 1) }
scope :query, ->(query) { includes(:work).where("class_name like ? OR message like ? OR status = ? OR works.doi = ?", "%#{query}%", "%#{query}%", query, query)
.references(:work) }
scope :total, ->(duration) { where("created_at > ?", Time.zone.now - duration.days) }
scope :total_errors, ->(duration) { where("alerts.level > ?", 0).where("created_at > ?", Time.zone.now - duration.days) }
scope :from_sources, ->(duration) { where("source_id IS NOT NULL").where("created_at > ?", Time.zone.now - duration.days) }
scope :total, ->(duration) { where("created_at > ?", Time.zone.now.beginning_of_day - duration.days) }
scope :total_errors, ->(duration) { where("alerts.level > ?", 1).where("created_at > ?", Time.zone.now.beginning_of_day - duration.days) }
scope :from_sources, ->(duration) { where("source_id IS NOT NULL").where("created_at > ?", Time.zone.now.beginning_of_day - duration.days) }

# alert level, default is ERROR
# adapted from http://www.ruby-doc.org/stdlib-2.1.2/libdoc/logger/rdoc/Logger.html
Expand Down
2 changes: 1 addition & 1 deletion app/models/api_request.rb
@@ -1,5 +1,5 @@
class ApiRequest < ActiveRecord::Base
scope :total, ->(duration) { where("created_at > ?", Time.zone.now - duration.hours) }
scope :total, ->(duration) { where("created_at > ?", Time.zone.now.beginning_of_hour - duration.hours) }

def self.per_page
1000
Expand Down
2 changes: 1 addition & 1 deletion app/models/api_response.rb
Expand Up @@ -10,7 +10,7 @@ class ApiResponse < ActiveRecord::Base

scope :unresolved, -> { where("unresolved = ?", true) }
scope :filter, ->(id) { where("unresolved = ?", true).where("id <= ?", id) }
scope :total, ->(duration) { where("created_at > ?", Time.zone.now - duration.hours) }
scope :total, ->(duration) { where("created_at > ?", Time.zone.now.beginning_of_hour - duration.hours) }
scope :decreasing, ->(source_ids) { where("event_count < previous_count").where(skipped: false).where(source_id: source_ids) }
scope :increasing, ->(number, source_ids) { where("update_interval IS NOT NULL").where("((event_count - previous_count) / update_interval) >= ?", number).where(source_id: source_ids) }
scope :slow, ->(number) { where("duration >= ?", number * 1000).where(skipped: false) }
Expand Down

0 comments on commit 3546579

Please sign in to comment.