Class: RakeAudit::Adapters::ActiveRecordAdapter
- Defined in:
- lib/rake_audit/adapters/active_record_adapter.rb
Overview
Persists and queries TaskExecutionRecord instances via ActiveRecord.
Instance Method Summary collapse
- #average_duration_ms ⇒ Float?
- #count ⇒ Integer
- #count_by_status(status) ⇒ Integer
- #find(id) ⇒ RakeAudit::TaskExecution
-
#query(filters: {}, page: nil, per_page: 25) ⇒ ActiveRecord::Relation
Kaminari-paginated relation.
-
#save(record) ⇒ Object
Create a TaskExecution row from the given record.
- #top_failed_tasks(limit: 10) ⇒ Array<Array(String, Integer)>
Methods inherited from Base
Instance Method Details
#average_duration_ms ⇒ Float?
57 58 59 |
# File 'lib/rake_audit/adapters/active_record_adapter.rb', line 57 def average_duration_ms RakeAudit::TaskExecution.average(:duration_ms) end |
#count ⇒ Integer
46 47 48 |
# File 'lib/rake_audit/adapters/active_record_adapter.rb', line 46 def count RakeAudit::TaskExecution.count end |
#count_by_status(status) ⇒ Integer
52 53 54 |
# File 'lib/rake_audit/adapters/active_record_adapter.rb', line 52 def count_by_status(status) RakeAudit::TaskExecution.where(status: status).count end |
#find(id) ⇒ RakeAudit::TaskExecution
39 40 41 42 43 |
# File 'lib/rake_audit/adapters/active_record_adapter.rb', line 39 def find(id) RakeAudit::TaskExecution.find(id) rescue ActiveRecord::RecordNotFound raise RakeAudit::RecordNotFound, "Couldn't find execution with id=#{id}" end |
#query(filters: {}, page: nil, per_page: 25) ⇒ ActiveRecord::Relation
Returns kaminari-paginated relation.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rake_audit/adapters/active_record_adapter.rb', line 24 def query(filters: {}, page: nil, per_page: 25) scope = RakeAudit::TaskExecution.order(started_at: :desc) EXACT_FILTERS.each do |col| scope = scope.where(col => filters[col]) if filters.key?(col) end scope = scope.where(started_at: filters[:from]..) if filters.key?(:from) scope = scope.where(started_at: ..filters[:to]) if filters.key?(:to) scope.page(page).per(per_page) end |
#save(record) ⇒ Object
Create a TaskExecution row from the given record.
16 17 18 |
# File 'lib/rake_audit/adapters/active_record_adapter.rb', line 16 def save(record) RakeAudit::TaskExecution.create!(record.to_h) end |
#top_failed_tasks(limit: 10) ⇒ Array<Array(String, Integer)>
63 64 65 66 67 68 69 70 |
# File 'lib/rake_audit/adapters/active_record_adapter.rb', line 63 def top_failed_tasks(limit: 10) RakeAudit::TaskExecution .where(status: 'failure') .group(:task_name) .count .sort_by { |_, c| -c } .first(limit) end |