Class: OutboundRequest
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- OutboundRequest
- Defined in:
- app/models/outbound_request.rb
Overview
Schema Information
Table name: outbound_requests
id :integer not null, primary key
service :string(255)
action :string(255)
identifier :string(255)
params :text
response_code :string(255)
response_body :text
error :text
created_at :datetime not null
updated_at :datetime not null
Class Method Summary collapse
- .delete_requests_older_than(age) ⇒ Object
- .response_summary(params = {}) ⇒ Object
- .rpm(params = {}) ⇒ Object
- .search(params) ⇒ Object
Instance Method Summary collapse
Class Method Details
.delete_requests_older_than(age) ⇒ Object
41 42 43 |
# File 'app/models/outbound_request.rb', line 41 def self.delete_requests_older_than(age) self.where('created_at < ?', (Time.now - age)).delete_all end |
.response_summary(params = {}) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/models/outbound_request.rb', line 64 def self.response_summary(params={}) period = params[:period] || 60 query = where('created_at > ?', Time.current - period.seconds) [:service, :action].each do |filter| if params[filter] query = query.where(filter => params[filter]) end end query.group('response_code').count end |
.rpm(params = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/outbound_request.rb', line 49 def self.rpm(params={}) period = params[:period] || 60 # period in seconds mins_per_period = period / 60.0 query = where('created_at > ?', Time.current - period.seconds) [:service, :action, :response_code].each do |filter| if params[filter] query = query.where(filter => params[filter]) end end query.count / mins_per_period end |
.search(params) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/models/outbound_request.rb', line 29 def self.search(params) identifier = params[:identifier] service = params[:service] action = params[:request_action] requests = self.order('created_at desc') requests = requests.partial_search(:identifier, identifier) if identifier.present? requests = requests.where(service: service) if service.present? requests = requests.where(action: action) if action.present? requests = requests.page(params[:page]) end |
Instance Method Details
#elapsed_time ⇒ Object
45 46 47 |
# File 'app/models/outbound_request.rb', line 45 def elapsed_time updated_at - created_at end |