sidekiq_monitor 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -101,8 +101,11 @@ class SidekiqMonitor.AbstractJobsTable
101
101
  </pre>
102
102
  """
103
103
  else if result?
104
- rows_html = "<tr><td>#{key}</td><td>#{value}</td></tr>" for key, value in result
104
+ rows_html = ''
105
+ for key, value of result
106
+ rows_html += "<tr><td>#{key}</td><td>#{JSON.stringify(value, null, 2)}</td></tr>"
105
107
  result_html = """
108
+ <h4>Result</h4>
106
109
  <table class="table table-striped">
107
110
  #{rows_html}
108
111
  </table>
@@ -116,6 +119,10 @@ class SidekiqMonitor.AbstractJobsTable
116
119
  </div>
117
120
  <div class="modal-body">
118
121
  <table class="table table-striped">
122
+ <tr>
123
+ <th>ID</th>
124
+ <td>#{id}</td>
125
+ </tr>
119
126
  <tr>
120
127
  <th>JID</th>
121
128
  <td>#{jid}</td>
@@ -3,6 +3,16 @@ module Sidekiq
3
3
  class JobsDatatable < AjaxDatatablesRails
4
4
  include ActionView::Helpers::DateHelper
5
5
 
6
+ @search_filters = []
7
+
8
+ class << self
9
+ attr_reader :search_filters
10
+
11
+ def add_search_filter(search_filter)
12
+ @search_filters << search_filter
13
+ end
14
+ end
15
+
6
16
  def initialize(view)
7
17
  @model_name = Sidekiq::Monitor::Job
8
18
  @columns = [
@@ -71,6 +81,50 @@ module Sidekiq
71
81
  def simplified_distance_of_time_in_words(from_time, to_time)
72
82
  distance_of_time_in_words(from_time, to_time, true).gsub('less than ', '').gsub('about ', '')
73
83
  end
84
+
85
+ def search_records(records)
86
+ if params[:sSearch].present?
87
+ records = apply_search_value_to_records(params[:sSearch], records)
88
+ end
89
+ conditions = @columns.each_with_index.map do |column, index|
90
+ value = params[:"sSearch_#{index}"]
91
+ search_condition(column, value) if value.present?
92
+ end
93
+ conditions = conditions.compact.reduce(:and)
94
+ records = records.where(conditions) if conditions.present?
95
+ records
96
+ end
97
+
98
+ def apply_search_value_to_records(search_value, records)
99
+ search_terms = []
100
+ search_value.split.each do |search_term|
101
+ filter_applied = false
102
+ self.class.search_filters.each do |search_filter|
103
+ if search_term =~ search_filter[:pattern]
104
+ records = search_filter[:filter].call(search_term, records)
105
+ filter_applied = true
106
+ break
107
+ end
108
+ end
109
+ search_terms << search_term unless filter_applied
110
+ end
111
+ value = search_terms.join(' ')
112
+ conditions = @searchable_columns.map do |column|
113
+ search_condition(column, value)
114
+ end
115
+ conditions = conditions.reduce(:or)
116
+ records = records.where(conditions)
117
+ records
118
+ end
119
+
120
+ def search_condition(column, value)
121
+ column = column.split('.').last
122
+ column_hash = @model_name.columns_hash[column]
123
+ if column_hash && [:string, :text].include?(column_hash.type)
124
+ return @model_name.arel_table[column].matches("%#{value}%")
125
+ end
126
+ @model_name.arel_table[column].eq(value)
127
+ end
74
128
  end
75
129
  end
76
130
  end
@@ -4,6 +4,8 @@ require 'ajax-datatables-rails'
4
4
 
5
5
  directory = File.dirname(File.absolute_path(__FILE__))
6
6
  Dir.glob("#{directory}/monitor/**/*.rb") { |file| require file }
7
+ # Require JobsDatatable to expose JobsDatatable.add_search_filter
8
+ Dir.glob("#{directory}/../../app/datatables/sidekiq/monitor/jobs_datatable.rb") { |file| require file }
7
9
 
8
10
  module Sidekiq
9
11
  module Monitor
@@ -45,6 +45,7 @@ module Sidekiq
45
45
  backtrace: exception.backtrace
46
46
  }
47
47
  job = find_job(msg)
48
+ return unless job
48
49
  job.update_attributes(
49
50
  finished_at: DateTime.now,
50
51
  status: 'failed',
@@ -54,6 +55,7 @@ module Sidekiq
54
55
 
55
56
  def complete(worker, msg, queue, return_value)
56
57
  job = find_job(msg)
58
+ return unless job
57
59
  job.update_attributes(
58
60
  finished_at: DateTime.now,
59
61
  status: 'complete',
@@ -15,6 +15,7 @@ module Sidekiq
15
15
  raise exception
16
16
  end
17
17
  @processor.complete(worker, msg, queue, return_value)
18
+ return_value
18
19
  end
19
20
  end
20
21
  end
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Monitor
3
- VERSION = '0.0.5'
3
+ VERSION = '0.0.6'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq_monitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-19 00:00:00.000000000 Z
12
+ date: 2013-07-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sidekiq
@@ -84,18 +84,10 @@ extra_rdoc_files: []
84
84
  files:
85
85
  - app/assets/javascripts/sidekiq/monitor/abstract_jobs_table.js.coffee
86
86
  - app/assets/javascripts/sidekiq/monitor/application.js.coffee
87
- - app/assets/javascripts/sidekiq/monitor/bootstrap-select.min.js
88
- - app/assets/javascripts/sidekiq/monitor/bootstrap.min.js
89
- - app/assets/javascripts/sidekiq/monitor/datatables.bootstrap.js
90
- - app/assets/javascripts/sidekiq/monitor/datatables.js
91
- - app/assets/javascripts/sidekiq/monitor/datatables.standing_redraw.js.coffee
92
87
  - app/assets/javascripts/sidekiq/monitor/initialize.js.coffee.erb
93
88
  - app/assets/javascripts/sidekiq/monitor/jobs_table.js.coffee
94
- - app/assets/javascripts/sidekiq/monitor/jquery.timeago.js
95
89
  - app/assets/javascripts/sidekiq/monitor/queue_jobs_table.js.coffee
96
90
  - app/assets/stylesheets/sidekiq/monitor/application.css.sass
97
- - app/assets/stylesheets/sidekiq/monitor/bootstrap-select.min.css
98
- - app/assets/stylesheets/sidekiq/monitor/bootstrap.min.css
99
91
  - app/assets/stylesheets/sidekiq/monitor/jobs_table.css.sass
100
92
  - app/assets/stylesheets/sidekiq/monitor/layout.css.sass
101
93
  - app/controllers/sidekiq/monitor/api/jobs_controller.rb
@@ -122,6 +114,14 @@ files:
122
114
  - lib/sidekiq/monitor/version.rb
123
115
  - lib/sidekiq/monitor.rb
124
116
  - lib/sidekiq_monitor.rb
117
+ - vendor/assets/javascripts/sidekiq/monitor/bootstrap-select.min.js
118
+ - vendor/assets/javascripts/sidekiq/monitor/bootstrap.min.js
119
+ - vendor/assets/javascripts/sidekiq/monitor/datatables.bootstrap.js
120
+ - vendor/assets/javascripts/sidekiq/monitor/datatables.js
121
+ - vendor/assets/javascripts/sidekiq/monitor/datatables.standing_redraw.js.coffee
122
+ - vendor/assets/javascripts/sidekiq/monitor/jquery.timeago.js
123
+ - vendor/assets/stylesheets/sidekiq/monitor/bootstrap-select.min.css
124
+ - vendor/assets/stylesheets/sidekiq/monitor/bootstrap.min.css
125
125
  - MIT-LICENSE
126
126
  - Rakefile
127
127
  - README.md