sidekiq-history 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c189112d4823a4d54d8a5a32f4b27e9060ca1a84
4
- data.tar.gz: 41e45ae2c8a55aa9e28d372ff01de40a02aa6772
3
+ metadata.gz: e960876faa26b6bc5144bf2651c229e9863f4c01
4
+ data.tar.gz: 41f8495091e1fa008ff9f19cf4165c0939544e3b
5
5
  SHA512:
6
- metadata.gz: 8e3aa1e54ad7d6987528ad19d5557f090dacf7bdefee24400ad6a80ca97349c668ab18b3c939096c17cc1e1528b2dcacfca91dce49eb3f052cd490e49b0e7d3b
7
- data.tar.gz: 8fd4405a7368e0fdf800298bbc66acbc71e51bfc8670322a593318469184258b299924825138e3c78d335cb3541305b77740c3d1b49786e9766f43c9b7704dcd
6
+ metadata.gz: de904b6ec8eae8dc5416d00c09c07af70eb0e5288a15f05c0d5a6020d8e1522f967b0587566b8fde41d2ae8d65fc9c13616b76c86ef3ee22163fd241a24a5d61
7
+ data.tar.gz: 87d356426ec6ab4025880a983d0d02c6dd501914f9e103a560710da04588eff2f9fbfc11866fd6a66ed6ae4db2874063c4e84ea7a311449fe404d816187ef155
data/README.md CHANGED
@@ -20,9 +20,9 @@ Or install it yourself as:
20
20
 
21
21
  Nothing left to do. Mount sidekiq, and go to the web interface. You'll see a shiny new History tab!
22
22
 
23
- By default it will keep history on the last 1000 jobs. To change that set `Sidekiq::History::Middleware::MAX_COUNT = 10000`. Be careful because the data is persisted in Redis Sorted Set and it WILL take up RAM. Max possible value is 4294967295 per Redis limit.
23
+ By default it will keep history on the last 1000 jobs. To change that set `Sidekiq.history_max_count = 10000`. Be careful because the data is persisted in Redis Sorted Set and it WILL take up RAM. Max possible value is 4294967295 per Redis limit.
24
24
 
25
- If you want to only record history for specific jobs you can set `Sidekiq::History::Middleware::EXCLUDE_JOBS = ['OneJob']` (do not record for specified jobs) and `Sidekiq::History::Middleware::INCLUDE_JOBS = ['AnotherJob']` (record ONLY jobs specified). INCLUDE will take precedence so if you set it to blank array nothing will be recorded.
25
+ If you want to only record history for specific jobs you can set `Sidekiq.history_exclude_jobs = ['OneJob']` (do not record for specified jobs) and `Sidekiq.history_include_jobs = ['AnotherJob']` (record ONLY jobs specified). INCLUDE will take precedence so if you set it to blank array nothing will be recorded.
26
26
 
27
27
  ## Screenshot
28
28
 
@@ -9,26 +9,51 @@ module Sidekiq
9
9
  end
10
10
 
11
11
  def self.history_max_count
12
- # => use default 1000 unless specified in config. Max is 4294967295 per Redis Sorted Set limit
13
- if defined? MAX_COUNT
14
- hmc = [MAX_COUNT, 4294967295].min
15
- else
16
- hmc = 1000
17
- end
12
+ # => use default 1000 unless specified in config.
13
+ # Max is 4294967295 per Redis Sorted Set limit
14
+ hmc = if defined? MAX_COUNT
15
+ [MAX_COUNT, 4_294_967_295].min
16
+ else
17
+ 1000
18
+ end
18
19
  return hmc if @history_max_count.nil?
19
20
  @history_max_count
20
21
  end
21
22
 
23
+ def self.history_exclude_jobs=(value)
24
+ @history_exclude_jobs = value
25
+ end
26
+
27
+ def self.history_exclude_jobs
28
+ if defined? Sidekiq::History::Middleware::EXCLUDE_JOBS
29
+ jobs = Sidekiq::History::Middleware::EXCLUDE_JOBS
30
+ end
31
+ return jobs if @history_exclude_jobs.nil?
32
+ @history_exclude_jobs
33
+ end
34
+
35
+ def self.history_include_jobs=(value)
36
+ @history_include_jobs = value
37
+ end
38
+
39
+ def self.history_include_jobs
40
+ if defined? Sidekiq::History::Middleware::INCLUDE_JOBS
41
+ jobs = Sidekiq::History::Middleware::INCLUDE_JOBS
42
+ end
43
+ return jobs if @history_include_jobs.nil?
44
+ @history_include_jobs
45
+ end
46
+
22
47
  module History
23
48
  LIST_KEY = :history
24
49
 
25
50
  def self.reset_history(options = {})
26
- Sidekiq.redis { |c|
51
+ Sidekiq.redis do |c|
27
52
  c.multi do
28
53
  c.del(LIST_KEY)
29
54
  c.set('stat:history', 0) if options[:counter] || options['counter']
30
55
  end
31
- }
56
+ end
32
57
  end
33
58
 
34
59
  def self.count
@@ -40,9 +65,7 @@ module Sidekiq
40
65
  super LIST_KEY
41
66
  end
42
67
  end
43
-
44
68
  end
45
-
46
69
  end
47
70
 
48
71
  Sidekiq.configure_server do |config|
@@ -7,14 +7,22 @@ module Sidekiq
7
7
 
8
8
  attr_accessor :msg
9
9
 
10
- def call(worker, msg, queue)
10
+ def call(_worker, msg, queue)
11
11
  self.msg = msg
12
- job_class = msg['class']
12
+
13
+ # Use the Sidekiq API to unwrap the job
14
+ job = Sidekiq::Job.new(msg)
15
+ job_class = job.display_class
16
+
17
+ # Setup a unwraped copy of the bare job data
18
+ payload = msg.dup
19
+ payload['class'] = job_class
20
+ payload['args'] = job.display_args
13
21
 
14
22
  data = {
15
23
  started_at: Time.now.utc,
16
- payload: msg,
17
- worker: msg['class'],
24
+ payload: payload,
25
+ worker: job_class,
18
26
  processor: "#{identity}-#{Thread.current.object_id}",
19
27
  queue: queue
20
28
  }
@@ -28,7 +36,8 @@ module Sidekiq
28
36
  list.each do |entry|
29
37
  migrated_data = JSON.parse(entry)
30
38
  if record_history(job_class) == true
31
- conn.zadd(LIST_KEY, data[:started_at].to_f, Sidekiq.dump_json(migrated_data))
39
+ conn.zadd(LIST_KEY, data[:started_at].to_f,
40
+ Sidekiq.dump_json(migrated_data))
32
41
  end
33
42
  end
34
43
  end
@@ -48,25 +57,17 @@ module Sidekiq
48
57
  private
49
58
 
50
59
  # check if this job should be recorded
51
- def record_history job_class
52
- # first check inclusion
53
- if defined? INCLUDE_JOBS
54
- if INCLUDE_JOBS.include? job_class
55
- return true
56
- else
57
- return false
58
- end
59
- elsif defined? EXCLUDE_JOBS
60
- if EXCLUDE_JOBS.include? job_class
61
- return false
62
- else
63
- return true
64
- end
65
- else
66
- return true
60
+ def record_history(job_class)
61
+ # first check inclusion, when present
62
+ # it will take precedence over exclude
63
+ if !Sidekiq.history_include_jobs.nil?
64
+ return Sidekiq.history_include_jobs.include?(job_class)
65
+ elsif !Sidekiq.history_exclude_jobs.nil?
66
+ return !Sidekiq.history_exclude_jobs.include?(job_class)
67
67
  end
68
- end
69
68
 
69
+ true
70
+ end
70
71
  end
71
72
  end
72
73
  end
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module History
3
- VERSION = "0.0.9"
3
+ VERSION = '0.0.10'.freeze
4
4
  end
5
5
  end
@@ -1,7 +1,7 @@
1
1
  module Sidekiq
2
2
  module History
3
3
  module WebExtension
4
- ROOT = File.expand_path('../../../../web', __FILE__)
4
+ ROOT = File.expand_path('../../../web', __dir__)
5
5
 
6
6
  def self.registered(app)
7
7
  app.get '/history' do
@@ -24,7 +24,9 @@
24
24
  <td>
25
25
  <%= relative_time(Time.parse(entry['started_at'])) %>
26
26
  </td>
27
- <td><%= entry.queue %></td>
27
+ <td>
28
+ <a href="<%= root_path %>queues/<%= entry.queue %>"><%= entry.queue %></a>
29
+ </td>
28
30
  <td>
29
31
  <%= entry['payload']['class'] %>
30
32
  </td>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-history
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Russ Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-26 00:00:00.000000000 Z
11
+ date: 2019-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  version: '0'
136
136
  requirements: []
137
137
  rubyforge_project:
138
- rubygems_version: 2.5.2
138
+ rubygems_version: 2.5.2.1
139
139
  signing_key:
140
140
  specification_version: 4
141
141
  summary: History for sidekiq jobs.