Class: Alert
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Alert
- Extended by:
- PaginationSearch::Pagination
- Defined in:
- app/models/alert.rb
Constant Summary collapse
- LOCATIONS_FOR_ATTRIBUTES =
{ title: { association: :query, column: :title, type: :text }, status: { association: :base, column: :status, type: :text }, description: { association: :base, column: :description, type: :text }, author: { association: :users, column: :name, type: :text }, updated_at: { association: :base, column: :updated_at, type: :time }, created_at: { association: :base, column: :created_at, type: :time } }.freeze
- INCLUDES_MODELS =
[:query_versions, :query, :last_alert_result, :users].freeze
- STATUSES =
OpenStruct.new( { pending: 'Pending', errored: 'Errored', passing: 'Passing', failing: 'Failing', paused: 'Paused' } )
- COMPARISON_FUNCTIONS =
{ '<' => :result_is_less_than_target, '>' => :result_is_greater_than_target, '=' => :result_is_equal_to_target }
- BAD_DATA_SIZE_MESSAGE =
'An alert result must return only a single row and a single column'- BAD_DATA_TYPE_MESSAGE =
'An alert must return a number'
Instance Attribute Summary collapse
-
#query_title ⇒ Object
Returns the value of attribute query_title.
Class Method Summary collapse
Instance Method Summary collapse
Methods included from PaginationSearch::Pagination
Instance Attribute Details
#query_title ⇒ Object
Returns the value of attribute query_title.
7 8 9 |
# File 'app/models/alert.rb', line 7 def query_title @query_title end |
Class Method Details
.run_all ⇒ Object
55 56 57 |
# File 'app/models/alert.rb', line 55 def self.run_all all.each(&:run) end |
Instance Method Details
#check_last_result ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'app/models/alert.rb', line 72 def check_last_result last_alert_result.reload return if error_from_result_failure data = last_alert_result.sample_data return if error_from_data_size(data) return unless value = to_number(data.first.first) set_status_from_outcome(value) end |
#error(message) ⇒ Object
65 66 67 68 69 70 |
# File 'app/models/alert.rb', line 65 def error() self.status = STATUSES.errored self. = save! send_failing_email end |
#run ⇒ Object
59 60 61 62 63 |
# File 'app/models/alert.rb', line 59 def run unless status == STATUSES.paused Resque.enqueue(AlertExecution, id, user.role) end end |