sidekiq_monitor 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,7 +4,7 @@ Advanced monitoring for Sidekiq
4
4
 
5
5
  Description
6
6
  -----------
7
- Sidekiq Monitor offers a detailed, malleable UI for monitoring Sidekiq jobs.
7
+ Sidekiq Monitor offers a detailed UI for monitoring Sidekiq jobs, letting you filter, search, and sort jobs by many attributes, view error backtraces, set job completion metadata, and more.
8
8
 
9
9
  It lets you:
10
10
 
@@ -30,6 +30,12 @@ And it looks like this:
30
30
 
31
31
  [<img src="https://raw.github.com/socialpandas/sidekiq_monitor/master/examples/screenshot.png" />](https://raw.github.com/socialpandas/sidekiq_monitor/master/examples/screenshot.png)
32
32
 
33
+ Sidekiq Monitor stores jobs using ActiveRecord, allowing you to perform complex queries and delete specific collections of jobs:
34
+
35
+ ```ruby
36
+ Sidekiq::Monitor::Job.where(queue: 'user_update').where('enqueued_at > ?', 2.days.ago).destroy_all
37
+ ```
38
+
33
39
  Installation
34
40
  ------------
35
41
 
@@ -58,8 +58,8 @@ class SidekiqMonitor.AbstractJobsTable
58
58
  @show_job(job)
59
59
  false
60
60
  @table.on 'click', '.retry-job', (e) =>
61
- jid = $(e.target).attr('data-job-jid')
62
- $.getJSON SidekiqMonitor.settings.api_url('jobs/retry?jid='+jid), =>
61
+ id = $(e.target).attr('data-job-id')
62
+ $.getJSON SidekiqMonitor.settings.api_url('jobs/retry/'+id), =>
63
63
  @reload_table()
64
64
  false
65
65
 
@@ -77,8 +77,10 @@ class SidekiqMonitor.AbstractJobsTable
77
77
  show_job: (job) =>
78
78
  return false if !job?
79
79
 
80
+ id = job[@columns.id]
80
81
  jid = job[@columns.jid]
81
82
  class_name = job[@columns.class_name]
83
+ name = job[@columns.name]
82
84
  started_at = job[@columns.started_at]
83
85
  duration = job[@columns.duration]
84
86
  status = job[@columns.status]
@@ -122,9 +124,13 @@ class SidekiqMonitor.AbstractJobsTable
122
124
  <th>Class</th>
123
125
  <td>#{class_name}</td>
124
126
  </tr>
127
+ <tr>
128
+ <th>Name</th>
129
+ <td>#{name}</td>
130
+ </tr>
125
131
  <tr>
126
132
  <th>Args</th>
127
- <td>#{args}</td>
133
+ <td>#{JSON.stringify(args, null, 2)}</td>
128
134
  </tr>
129
135
  <tr>
130
136
  <th>Started</th>
@@ -140,12 +146,23 @@ class SidekiqMonitor.AbstractJobsTable
140
146
  </tr>
141
147
  </table>
142
148
  #{result_html}
149
+ <div class="job-custom-views"></div>
143
150
  </div>
144
151
  </div>
145
152
  """
146
153
  $('.job-modal').modal('hide')
147
154
  $('body').append(modal_html)
148
- $('.job-modal:last').modal()
155
+ modal = $('.job-modal:last')
156
+ modal.modal
157
+ width: 480
158
+ $.getJSON SidekiqMonitor.settings.api_url("jobs/custom_views/#{id}"), (views) ->
159
+ html = ''
160
+ for view in views
161
+ html += """
162
+ <h4>#{view['name']}</h4>
163
+ #{view['html']}
164
+ """
165
+ $('.job-custom-views', modal).html(html)
149
166
 
150
167
  on_poll: =>
151
168
  @reload_table()
@@ -4,18 +4,20 @@ class SidekiqMonitor.JobsTable extends SidekiqMonitor.AbstractJobsTable
4
4
  options =
5
5
  table_selector: 'table.jobs'
6
6
  columns:
7
- jid: 0
8
- queue: 1
9
- class_name: 2
10
- name: 3
11
- enqueued_at: 4
12
- started_at: 5
13
- duration: 6
14
- message: 7
15
- status: 8
16
- result: 9
17
- args: 10
7
+ id: 0
8
+ jid: 1
9
+ queue: 2
10
+ class_name: 3
11
+ name: 4
12
+ enqueued_at: 5
13
+ started_at: 6
14
+ duration: 7
15
+ message: 8
16
+ status: 9
17
+ result: 10
18
+ args: 11
18
19
  column_options: [
20
+ { bVisible: false }
19
21
  { bVisible: false }
20
22
  null
21
23
  null
@@ -44,7 +46,7 @@ class SidekiqMonitor.JobsTable extends SidekiqMonitor.AbstractJobsTable
44
46
  'info'
45
47
  html = """<a href="#" class="btn btn-#{class_name} btn-mini status-value">#{oObj.aData[@columns.status]}</a>"""
46
48
  if status == 'failed'
47
- html += """<a href="#" class="btn btn-mini btn-primary retry-job" data-job-jid="#{oObj.aData[0]}">Retry<a>"""
49
+ html += """<a href="#" class="btn btn-mini btn-primary retry-job" data-job-id="#{oObj.aData[@columns.id]}">Retry<a>"""
48
50
  """<span class="action-buttons">#{html}</span>"""
49
51
  }
50
52
  { bVisible: false }
@@ -4,18 +4,20 @@ class SidekiqMonitor.QueuesTable extends SidekiqMonitor.AbstractJobsTable
4
4
  options =
5
5
  table_selector: 'table.queue-jobs'
6
6
  columns:
7
- jid: 0
8
- queue: 1
9
- class_name: 2
10
- name: 3
11
- enqueued_at: 4
12
- started_at: 5
13
- duration: 6
14
- message: 7
15
- status: 8
16
- result: 9
17
- args: 10
7
+ id: 0
8
+ jid: 1
9
+ queue: 2
10
+ class_name: 3
11
+ name: 4
12
+ enqueued_at: 5
13
+ started_at: 6
14
+ duration: 7
15
+ message: 8
16
+ status: 9
17
+ result: 10
18
+ args: 11
18
19
  column_options: [
20
+ { bVisible: false }
19
21
  { bVisible: false }
20
22
  { bVisible: false }
21
23
  null
@@ -44,7 +46,7 @@ class SidekiqMonitor.QueuesTable extends SidekiqMonitor.AbstractJobsTable
44
46
  'info'
45
47
  html = """<a href="#" class="btn btn-#{class_name} btn-mini status-value">#{oObj.aData[@columns.status]}</a>"""
46
48
  if status == 'failed'
47
- html += """<a href="#" class="btn btn-mini btn-primary retry-job" data-job-jid="#{oObj.aData[0]}">Retry<a>"""
49
+ html += """<a href="#" class="btn btn-mini btn-primary retry-job" data-job-id="#{oObj.aData[@columns.id]}">Retry<a>"""
48
50
  """<span class="action-buttons">#{html}</span>"""
49
51
  }
50
52
  { bVisible: false }
@@ -8,11 +8,25 @@ module Sidekiq
8
8
  render json: JobsDatatable.new(view_context)
9
9
  end
10
10
 
11
+ def custom_views
12
+ job = Job.find(params[:id])
13
+ render json: {}, status: 404 and return if job.blank?
14
+
15
+ views = CustomViews.for_job(job)
16
+ views = views.collect do |view|
17
+ {
18
+ name: view[:name],
19
+ html: render_to_string(view[:path], locals: {job: job, path: view[:path]})
20
+ }
21
+ end
22
+ render json: views, status: :ok
23
+ end
24
+
11
25
  def retry
12
- jid = params[:jid]
13
- render json: {}, status: 404 and return if jid.blank?
26
+ id = params[:id]
27
+ render json: {}, status: 404 and return if id.blank?
14
28
 
15
- job = Job.find_by_jid(jid)
29
+ job = Job.find(id)
16
30
  render json: {}, status: 404 and return if job.blank?
17
31
 
18
32
  args = job.args
@@ -6,6 +6,7 @@ module Sidekiq
6
6
  def initialize(view)
7
7
  @model_name = Sidekiq::Monitor::Job
8
8
  @columns = [
9
+ 'sidekiq_jobs.id',
9
10
  'sidekiq_jobs.jid',
10
11
  'sidekiq_jobs.queue',
11
12
  'sidekiq_jobs.class_name',
@@ -33,6 +34,7 @@ module Sidekiq
33
34
  def data
34
35
  jobs.map do |job|
35
36
  [
37
+ job.id,
36
38
  job.jid,
37
39
  job.queue,
38
40
  job.class_name,
@@ -1,6 +1,7 @@
1
1
  table class="jobs-table jobs table table-hover table-bordered table-striped table-white" data-source="#{root_path}api/jobs"
2
2
  thead
3
3
  th ID
4
+ th JID
4
5
  th Queue
5
6
  th Class
6
7
  th Name
@@ -1,6 +1,7 @@
1
1
  table class="jobs-table queue-jobs table table-hover table-bordered table-striped table-white" data-source="#{root_path}api/jobs"
2
2
  thead
3
3
  th ID
4
+ th JID
4
5
  th Queue
5
6
  th Class
6
7
  th Name
@@ -4,7 +4,7 @@ Sidekiq::Monitor::Engine.routes.draw do
4
4
 
5
5
  namespace 'api' do
6
6
  match '/jobs' => 'jobs#index'
7
- match '/jobs/:action' => 'jobs'
7
+ match '/jobs/:action(/:id)' => 'jobs'
8
8
  match '/queues/:queue' => 'queues#show'
9
9
  end
10
10
  end
@@ -1,4 +1,6 @@
1
1
  require 'slim'
2
+ require 'jquery-datatables-rails'
3
+ require 'ajax-datatables-rails'
2
4
 
3
5
  directory = File.dirname(File.absolute_path(__FILE__))
4
6
  Dir.glob("#{directory}/monitor/**/*.rb") { |file| require file }
@@ -0,0 +1,26 @@
1
+ module Sidekiq
2
+ module Monitor
3
+ class CustomViews
4
+ @views = []
5
+
6
+ class << self
7
+ def add(name, path, &block)
8
+ @views << {
9
+ name: name,
10
+ path: path,
11
+ filter: block
12
+ }
13
+ end
14
+
15
+ def for_job(job)
16
+ views = []
17
+ @views.each do |view|
18
+ is_valid = view[:filter].call(job)
19
+ views << view.dup if is_valid
20
+ end
21
+ views
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -19,6 +19,7 @@ module Sidekiq
19
19
  def start(worker, msg, queue)
20
20
  jid = msg['jid']
21
21
  args = msg['args']
22
+ now = DateTime.now
22
23
  job = Sidekiq::Monitor::Job.find_by_jid(jid)
23
24
  if job.blank?
24
25
  name = job_name(worker.class, args)
@@ -28,11 +29,12 @@ module Sidekiq
28
29
  class_name: worker.class.name,
29
30
  args: args,
30
31
  retry: msg['retry'],
32
+ enqueued_at: now,
31
33
  name: name
32
34
  )
33
35
  end
34
36
  job.update_attributes(
35
- started_at: DateTime.now,
37
+ started_at: now,
36
38
  status: 'running'
37
39
  )
38
40
  end
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Monitor
3
- VERSION = '0.0.3'
3
+ VERSION = '0.0.4'
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.3
4
+ version: 0.0.4
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-06-06 00:00:00.000000000 Z
12
+ date: 2013-07-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sidekiq
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: jquery-datatables-rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: ajax-datatables-rails
48
64
  requirement: !ruby/object:Gem::Requirement
@@ -99,6 +115,7 @@ files:
99
115
  - lib/generators/sidekiq/monitor/install/templates/create_sidekiq_jobs.rb
100
116
  - lib/sidekiq/monitor/cleaner.rb
101
117
  - lib/sidekiq/monitor/client/middleware.rb
118
+ - lib/sidekiq/monitor/custom_views.rb
102
119
  - lib/sidekiq/monitor/engine.rb
103
120
  - lib/sidekiq/monitor/processor.rb
104
121
  - lib/sidekiq/monitor/server/middleware.rb