sidekiq_monitor 0.0.9 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -0
- data/app/assets/javascripts/sidekiq/monitor/abstract_jobs_table.js.coffee +13 -1
- data/app/assets/javascripts/sidekiq/monitor/graph.js.coffee +1 -1
- data/app/assets/javascripts/sidekiq/monitor/initialize.js.coffee.erb +1 -0
- data/app/models/sidekiq/monitor/job.rb +1 -1
- data/app/views/sidekiq/monitor/layouts/application.slim +3 -1
- data/lib/sidekiq/monitor/processor.rb +65 -49
- data/lib/sidekiq/monitor/version.rb +1 -1
- data/lib/sidekiq/monitor.rb +3 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -113,6 +113,15 @@ Sidekiq::Monitor.options[:graphs] = {
|
|
113
113
|
|
114
114
|
`ALL` and `OTHER` are special keys: `ALL` will show all queues and `OTHER` will show all queues that aren't matched by the regex keys.
|
115
115
|
|
116
|
+
#### Poll Interval
|
117
|
+
|
118
|
+
The UI uses polling to update its data. By default, the polling interval is 3000ms, but you can adjust this like so:
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
# config/initializers/sidekiq_monitor.rb
|
122
|
+
Sidekiq::Monitor.options[:poll_interval] = 5000
|
123
|
+
```
|
124
|
+
|
116
125
|
### Authentication
|
117
126
|
|
118
127
|
You'll likely want to restrict access to this interface in a production setting. To do this, you can use routing constraints:
|
@@ -91,9 +91,21 @@ class SidekiqMonitor.AbstractJobsTable
|
|
91
91
|
|
92
92
|
result_html = ''
|
93
93
|
if status == 'failed'
|
94
|
+
rows_html = ''
|
95
|
+
for key, value of result
|
96
|
+
if key != 'message' && key != 'backtrace'
|
97
|
+
rows_html += "<tr><td>#{key}</td><td>#{JSON.stringify(value, null, 2)}</td></tr>"
|
98
|
+
if rows_html
|
99
|
+
rows_html = """
|
100
|
+
<h4>Result</h4>
|
101
|
+
<table class="table table-striped">
|
102
|
+
#{rows_html}
|
103
|
+
</table>
|
104
|
+
"""
|
94
105
|
result_html = """
|
95
106
|
<h4>Error</h4>
|
96
107
|
#{result.message}
|
108
|
+
#{rows_html}
|
97
109
|
<h5>Backtrace</h5>
|
98
110
|
<pre>
|
99
111
|
#{result.backtrace.join("\n")}
|
@@ -180,7 +192,7 @@ class SidekiqMonitor.AbstractJobsTable
|
|
180
192
|
start_polling: =>
|
181
193
|
setInterval =>
|
182
194
|
@on_poll()
|
183
|
-
,
|
195
|
+
, SidekiqMonitor.settings.poll_interval
|
184
196
|
|
185
197
|
format_time_ago: (time) =>
|
186
198
|
if time?
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Sidekiq
|
2
2
|
module Monitor
|
3
3
|
class Job < ActiveRecord::Base
|
4
|
-
attr_accessible :args, :class_name, :enqueued_at, :finished_at, :jid, :name, :queue, :result, :retry, :started_at, :status if ActiveRecord::VERSION::MAJOR < 4
|
4
|
+
attr_accessible :args, :class_name, :enqueued_at, :finished_at, :jid, :name, :queue, :result, :retry, :started_at, :status if ActiveRecord::VERSION::MAJOR < 4 || ActiveRecord.constants.include?(:MassAssignmentSecurity)
|
5
5
|
|
6
6
|
serialize :args
|
7
7
|
serialize :result
|
@@ -2,60 +2,25 @@ module Sidekiq
|
|
2
2
|
module Monitor
|
3
3
|
class Processor
|
4
4
|
def queue(worker_class, item, queue)
|
5
|
-
|
6
|
-
|
7
|
-
Sidekiq::Monitor::Job.find_or_create_by_jid(
|
8
|
-
jid: item['jid'],
|
9
|
-
queue: queue,
|
10
|
-
class_name: worker_class.is_a?(String) ? worker_class : worker_class.name,
|
11
|
-
args: args,
|
12
|
-
retry: item['retry'],
|
13
|
-
enqueued_at: DateTime.now,
|
14
|
-
status: 'queued',
|
15
|
-
name: name
|
16
|
-
)
|
5
|
+
job = find_or_initialize_job(worker_class, item, queue)
|
6
|
+
job.save
|
17
7
|
end
|
18
8
|
|
19
|
-
def start(worker,
|
20
|
-
|
21
|
-
args = msg['args']
|
22
|
-
now = DateTime.now
|
23
|
-
job = Sidekiq::Monitor::Job.find_by_jid(jid)
|
24
|
-
if job.blank?
|
25
|
-
name = job_name(worker.class, args)
|
26
|
-
job = Sidekiq::Monitor::Job.new(
|
27
|
-
jid: jid,
|
28
|
-
queue: queue,
|
29
|
-
class_name: worker.class.name,
|
30
|
-
args: args,
|
31
|
-
retry: msg['retry'],
|
32
|
-
enqueued_at: now,
|
33
|
-
name: name
|
34
|
-
)
|
35
|
-
end
|
9
|
+
def start(worker, item, queue)
|
10
|
+
job = find_or_initialize_job(worker, item, queue)
|
36
11
|
job.update_attributes(
|
37
|
-
started_at: now,
|
12
|
+
started_at: DateTime.now,
|
38
13
|
status: 'running'
|
39
14
|
)
|
40
15
|
end
|
41
16
|
|
42
|
-
def error(worker,
|
43
|
-
|
44
|
-
|
45
|
-
backtrace: exception.backtrace
|
46
|
-
}
|
47
|
-
job = find_job(msg)
|
48
|
-
return unless job
|
49
|
-
job.update_attributes(
|
50
|
-
finished_at: DateTime.now,
|
51
|
-
status: 'failed',
|
52
|
-
result: result
|
53
|
-
)
|
17
|
+
def error(worker, item, queue, exception)
|
18
|
+
job = find_or_initialize_job(worker, item, queue)
|
19
|
+
set_error(job, exception)
|
54
20
|
end
|
55
21
|
|
56
|
-
def complete(worker,
|
57
|
-
job =
|
58
|
-
return unless job
|
22
|
+
def complete(worker, item, queue, return_value)
|
23
|
+
job = find_or_initialize_job(worker, item, queue)
|
59
24
|
job.update_attributes(
|
60
25
|
finished_at: DateTime.now,
|
61
26
|
status: 'complete',
|
@@ -65,12 +30,63 @@ module Sidekiq
|
|
65
30
|
|
66
31
|
protected
|
67
32
|
|
68
|
-
def
|
69
|
-
|
33
|
+
def find_or_initialize_job(worker, item, queue, options={})
|
34
|
+
defaults = {
|
35
|
+
set_name: true
|
36
|
+
}
|
37
|
+
options.reverse_merge!(defaults)
|
38
|
+
|
39
|
+
worker_class = nil
|
40
|
+
if worker.is_a?(String)
|
41
|
+
worker_class = worker.constantize
|
42
|
+
elsif worker.is_a?(Class)
|
43
|
+
worker_class = worker
|
44
|
+
else
|
45
|
+
worker_class = worker.class
|
46
|
+
end
|
47
|
+
|
48
|
+
job = Sidekiq::Monitor::Job.find_by_jid(item['jid'])
|
49
|
+
if job.blank?
|
50
|
+
attributes = {
|
51
|
+
jid: item['jid'],
|
52
|
+
queue: queue,
|
53
|
+
class_name: worker_class.name,
|
54
|
+
args: item['args'],
|
55
|
+
retry: item['retry'],
|
56
|
+
enqueued_at: DateTime.now,
|
57
|
+
status: 'queued'
|
58
|
+
}
|
59
|
+
if options[:set_name] == true
|
60
|
+
attributes[:name] = job_name(worker_class, item, queue)
|
61
|
+
end
|
62
|
+
job = Sidekiq::Monitor::Job.new(attributes)
|
63
|
+
end
|
64
|
+
job
|
65
|
+
end
|
66
|
+
|
67
|
+
def job_name(worker_class, item, queue)
|
68
|
+
args = item['args']
|
69
|
+
begin
|
70
|
+
worker_class.respond_to?(:job_name) ? worker_class.job_name(*args) : nil
|
71
|
+
rescue Exception => exception
|
72
|
+
# If the job doesn't exist yet, we'll need to create it
|
73
|
+
job = find_or_initialize_job(worker_class, item, queue, set_name: false)
|
74
|
+
set_error(job, exception)
|
75
|
+
raise exception
|
76
|
+
end
|
70
77
|
end
|
71
78
|
|
72
|
-
def
|
73
|
-
|
79
|
+
def set_error(job, exception)
|
80
|
+
result = job.result.present? ? job.result.symbolize_keys : {}
|
81
|
+
result.merge!({
|
82
|
+
message: "#{exception.class.name}: #{exception.message}",
|
83
|
+
backtrace: exception.backtrace
|
84
|
+
})
|
85
|
+
job.update_attributes(
|
86
|
+
finished_at: DateTime.now,
|
87
|
+
status: 'failed',
|
88
|
+
result: result
|
89
|
+
)
|
74
90
|
end
|
75
91
|
end
|
76
92
|
end
|
data/lib/sidekiq/monitor.rb
CHANGED
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.
|
4
|
+
version: 0.1.1
|
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:
|
12
|
+
date: 2014-03-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sidekiq
|