sidekiq-status 0.4.0 → 0.5.0

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: 70899fafcf4e5aa712b2df57e34700cba6d001fe
4
- data.tar.gz: cd4801e8d4678b515f3a597438953c3430066a30
3
+ metadata.gz: c4b871d99e1ab00e5786f91d61a3f0fc4c17087e
4
+ data.tar.gz: 6909a5063a68811982f9e38580b1aeb146f5313f
5
5
  SHA512:
6
- metadata.gz: 1669fb78f47cc77930d4b93f7c7a1537526d426cf0e99c4c5bb8b13e271ed66711e15276959a381216710aca8cfac60f90fc0790719db2c9a8f4c3faaa046a41
7
- data.tar.gz: d7e697fdb8ee26e50f125b73b44abe2f5c796e74ad9242d76bc85964e526c33b9d81916fa49a3623c29bb55b2b9a5126b30db8e730c5668d34d1a6f7dbcfd024
6
+ metadata.gz: 952fb2284e645179db9b5242bf4a9adcc6f8512b02335b60056b964711498c2c87d633e6f1b95116d576524ca4e3931db25fa51a22eab4d67cc41ac86e84099f
7
+ data.tar.gz: 249eba2c142648813996c685d6bb5e03b08765580bd36139ce24f348ddc3a1cd19ec0569a9c398d9c08a2d948a2f64d7e537695df6d93b45869416a1546a16ef
data/CHANGELOG CHANGED
@@ -1 +1,2 @@
1
+ Version 0.5.0:Sidekiq v3 support, redis pools support
1
2
  Version 0.4.0:WebUI added, per-worker expiration setting enabled
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Sidekiq::Status
2
-
2
+ [![Gem Version](https://badge.fury.io/rb/sidekiq-status.png)](http://badge.fury.io/rb/sidekiq-status)
3
3
  [![Code Climate](https://codeclimate.com/github/utgarda/sidekiq-status.png)](https://codeclimate.com/github/utgarda/sidekiq-status)
4
4
  [![Build Status](https://secure.travis-ci.org/utgarda/sidekiq-status.png)](http://travis-ci.org/utgarda/sidekiq-status)
5
5
 
@@ -92,7 +92,8 @@ class MyJob
92
92
  # your code goes here
93
93
 
94
94
  # the common idiom to track progress of your task
95
- at 5, 100, "Almost done"
95
+ total 100 # by default
96
+ at 5, "Almost done"
96
97
 
97
98
  # a way to associate data with your job
98
99
  store vino: 'veritas'
@@ -107,7 +108,7 @@ job_id = MyJob.perform_async(*args)
107
108
  data = Sidekiq::Status::get_all job_id
108
109
  data # => {status: 'complete', update_time: 1360006573, vino: 'veritas'}
109
110
  Sidekiq::Status::get job_id, :vino #=> 'veritas'
110
- Sidekiq::Status::num job_id #=> 5
111
+ Sidekiq::Status::at job_id #=> 5
111
112
  Sidekiq::Status::total job_id #=> 100
112
113
  Sidekiq::Status::message job_id #=> "Almost done"
113
114
  Sidekiq::Status::pct_complete job_id #=> 5
@@ -121,6 +122,18 @@ Sidekiq::Status.cancel scheduled_job_id #=> true
121
122
  Sidekiq::Status.unschedule scheduled_job_id #=> true
122
123
  ```
123
124
 
125
+ ### Sidekiq web integration
126
+
127
+ Sidekiq::Status also provides an extension to Sidekiq web interface with a `/statuses` page.
128
+
129
+ Setup Sidekiq web interface according to Sidekiq documentation and add the Sidekiq::Status::Web require:
130
+
131
+ ``` ruby
132
+ require 'sidekiq/web'
133
+ require 'sidekiq-status/web'
134
+ ```
135
+
136
+
124
137
  ### Testing
125
138
 
126
139
  Drawing analogy from [sidekiq testing by inlining](https://github.com/mperham/sidekiq/wiki/Testing#testing-workers-inline),
@@ -45,8 +45,8 @@ module Sidekiq::Status
45
45
  end
46
46
 
47
47
  # Methods for retrieving job completion
48
- def num(job_id)
49
- get(job_id, :num).to_i
48
+ def at(job_id)
49
+ get(job_id, :at).to_i
50
50
  end
51
51
 
52
52
  def total(job_id)
@@ -54,7 +54,7 @@ module Sidekiq::Status
54
54
  end
55
55
 
56
56
  def pct_complete(job_id)
57
- (num(job_id).to_f / total(job_id)) * 100
57
+ (at(job_id).to_f / total(job_id)) * 100
58
58
  end
59
59
 
60
60
  def message(job_id)
@@ -6,8 +6,9 @@ module Sidekiq::Status
6
6
  # @param [Class] worker_class if includes Sidekiq::Status::Worker, the job gets processed with the plugin
7
7
  # @param [Array] msg job arguments
8
8
  # @param [String] queue the queue's name
9
- def call(worker_class, msg, queue)
10
- store_status msg['jid'], :queued
9
+ # @param [ConnectionPool] redis_pool optional redis connection pool
10
+ def call(worker_class, msg, queue, redis_pool=nil)
11
+ store_status msg['jid'], :queued, nil, redis_pool
11
12
  yield
12
13
  end
13
14
  end
@@ -8,9 +8,11 @@ module Sidekiq::Status::Storage
8
8
  # sets last update time
9
9
  # @param [String] id job id
10
10
  # @param [Hash] status_updates updated values
11
+ # @param [Integer] expiration optional expire time in seconds
12
+ # @param [ConnectionPool] redis_pool optional redis connection pool
11
13
  # @return [String] Redis operation status code
12
- def store_for_id(id, status_updates, expiration = nil)
13
- Sidekiq.redis do |conn|
14
+ def store_for_id(id, status_updates, expiration = nil, redis_pool=nil)
15
+ redis_connection(redis_pool) do |conn|
14
16
  conn.multi do
15
17
  conn.hmset id, 'update_time', Time.now.to_i, *(status_updates.to_a.flatten(1))
16
18
  conn.expire id, (expiration || Sidekiq::Status::DEFAULT_EXPIRY)
@@ -23,9 +25,11 @@ module Sidekiq::Status::Storage
23
25
  # only in case of :failed or :stopped job
24
26
  # @param [String] id job id
25
27
  # @param [Symbol] job status
28
+ # @param [Integer] expiration optional expire time in seconds
29
+ # @param [ConnectionPool] redis_pool optional redis connection pool
26
30
  # @return [String] Redis operation status code
27
- def store_status(id, status, expiration = nil)
28
- store_for_id id, {status: status}, expiration
31
+ def store_status(id, status, expiration = nil, redis_pool=nil)
32
+ store_for_id id, {status: status}, expiration, redis_pool
29
33
  end
30
34
 
31
35
  # Unschedules the job and deletes the Status
@@ -90,4 +94,18 @@ module Sidekiq::Status::Storage
90
94
  scheduled_jobs.each { |job_listing| (return job_listing) if job_listing.include?("\"jid\":\"#{job_id}") }
91
95
  nil
92
96
  end
97
+
98
+ # Yields redis connection. Uses redis pool if available.
99
+ # @param [ConnectionPool] redis_pool optional redis connection pool
100
+ def redis_connection(redis_pool=nil)
101
+ if redis_pool
102
+ redis_pool.with do |conn|
103
+ yield conn
104
+ end
105
+ else
106
+ Sidekiq.redis do |conn|
107
+ yield conn
108
+ end
109
+ end
110
+ end
93
111
  end
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Status
3
- VERSION = "0.4.0"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
@@ -19,14 +19,14 @@ module Sidekiq::Status
19
19
  queue = Sidekiq::Workers.new
20
20
  @statuses = []
21
21
 
22
- queue.each do |name, work, started_at|
22
+ queue.each do |process, name, work, started_at|
23
23
  job = Struct.new(:jid, :klass, :args).new(work["payload"]["jid"], work["payload"]["class"], work["payload"]["args"])
24
24
  status = Sidekiq::Status::get_all job.jid
25
- next if !status || status.count <= 2
25
+ next if !status || status.count < 2
26
26
  status["worker"] = job.klass
27
27
  status["args"] = job.args
28
28
  status["jid"] = job.jid
29
- status["pct_complete"] = ((status["num"].to_f / status["total"].to_f) * 100).to_i
29
+ status["pct_complete"] = ((status["at"].to_f / status["total"].to_f) * 100).to_i if status["total"].to_f > 0
30
30
  @statuses << OpenStruct.new(status)
31
31
  end
32
32
 
@@ -43,4 +43,4 @@ if Sidekiq::Web.tabs.is_a?(Array)
43
43
  Sidekiq::Web.tabs << "statuses"
44
44
  else
45
45
  Sidekiq::Web.tabs["Statuses"] = "statuses"
46
- end
46
+ end
@@ -24,11 +24,18 @@ module Sidekiq::Status::Worker
24
24
  # Sets current task progress
25
25
  # (inspired by resque-status)
26
26
  # @param Fixnum number of tasks done
27
- # @param Fixnum total number of tasks
28
27
  # @param String optional message
29
28
  # @return [String]
30
- def at(num, total, message=nil)
31
- store({num: num, total: total, message: message})
29
+ def at(num, message = nil)
30
+ total(100) if retrieve(:total).nil?
31
+ store(at: num, message: message)
32
+ end
33
+
34
+ # Sets total number of tasks
35
+ # @param Fixnum total number of tasks
36
+ # @return [String]
37
+ def total(num)
38
+ store(total: num)
32
39
  end
33
40
 
34
41
  end
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.require_paths = ['lib']
15
15
  gem.version = Sidekiq::Status::VERSION
16
16
 
17
- gem.add_dependency 'sidekiq', '~> 2.7'
17
+ gem.add_dependency 'sidekiq', '>= 2.7', '< 3.1'
18
18
  gem.add_development_dependency 'rake'
19
19
  gem.add_development_dependency 'rspec'
20
20
  end
@@ -22,5 +22,20 @@ describe Sidekiq::Status::ClientMiddleware do
22
22
  (1..Sidekiq::Status::DEFAULT_EXPIRY).should cover redis.ttl(job_id)
23
23
  end
24
24
 
25
+ context "when redis_pool passed" do
26
+ it "uses redis_pool" do
27
+ redis_pool = double(:redis_pool)
28
+ redis_pool.should_receive(:with)
29
+ Sidekiq.should_not_receive(:redis)
30
+ Sidekiq::Status::ClientMiddleware.new.call(StubJob, {'jid' => SecureRandom.hex}, :queued, redis_pool) do end
31
+ end
32
+ end
33
+
34
+ context "when redis_pool is not passed" do
35
+ it "uses Sidekiq.redis" do
36
+ Sidekiq.should_receive(:redis)
37
+ Sidekiq::Status::ClientMiddleware.new.call(StubJob, {'jid' => SecureRandom.hex}, :queued) do end
38
+ end
39
+ end
25
40
  end
26
- end
41
+ end
@@ -48,7 +48,7 @@ describe Sidekiq::Status do
48
48
  end
49
49
  end
50
50
 
51
- describe ".num, .total, .pct_complete, .message" do
51
+ describe ".at, .total, .pct_complete, .message" do
52
52
  it "should return job progress with correct type to it" do
53
53
  SecureRandom.should_receive(:hex).once.and_return(job_id)
54
54
 
@@ -57,7 +57,7 @@ describe Sidekiq::Status do
57
57
  ProgressJob.perform_async.should == job_id
58
58
  }.should == [job_id]*3
59
59
  end
60
- Sidekiq::Status.num(job_id).should == 100
60
+ Sidekiq::Status.at(job_id).should == 100
61
61
  Sidekiq::Status.total(job_id).should == 500
62
62
  Sidekiq::Status.pct_complete(job_id).should == 20
63
63
  Sidekiq::Status.message(job_id).should == 'howdy, partner?'
@@ -25,7 +25,8 @@ end
25
25
 
26
26
  class ProgressJob < StubJob
27
27
  def perform
28
- at 100, 500, 'howdy, partner?'
28
+ total 500
29
+ at 100, 'howdy, partner?'
29
30
  sleep 0.1
30
31
  end
31
32
  end
@@ -9,7 +9,7 @@
9
9
  <th>Progress</th>
10
10
  <th>Message</th>
11
11
  </tr>
12
- <% @statuses.each do |container| -%>
12
+ <% @statuses.each do |container| %>
13
13
  <tr>
14
14
  <td>
15
15
  <%= container.worker %>
@@ -27,10 +27,10 @@ color: white;">
27
27
  </div>
28
28
  <td><%= container.message %></td>
29
29
  </tr>
30
- <% end -%>
31
- <% if @statuses.empty? -%>
30
+ <% end %>
31
+ <% if @statuses.empty? %>
32
32
  <tr>
33
33
  <td colspan="6"></td>
34
34
  </tr>
35
- <% end -%>
36
- </table>
35
+ <% end %>
36
+ </table>
metadata CHANGED
@@ -1,55 +1,61 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-status
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeniy Tsvigun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-11 00:00:00.000000000 Z
11
+ date: 2014-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.7'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3.1'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - ~>
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '2.7'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.1'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rake
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - '>='
37
+ - - ">="
32
38
  - !ruby/object:Gem::Version
33
39
  version: '0'
34
40
  type: :development
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
- - - '>='
44
+ - - ">="
39
45
  - !ruby/object:Gem::Version
40
46
  version: '0'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: rspec
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
- - - '>='
51
+ - - ">="
46
52
  - !ruby/object:Gem::Version
47
53
  version: '0'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
- - - '>='
58
+ - - ">="
53
59
  - !ruby/object:Gem::Version
54
60
  version: '0'
55
61
  description:
@@ -59,9 +65,9 @@ executables: []
59
65
  extensions: []
60
66
  extra_rdoc_files: []
61
67
  files:
62
- - .gitignore
63
- - .rspec
64
- - .travis.yml
68
+ - ".gitignore"
69
+ - ".rspec"
70
+ - ".travis.yml"
65
71
  - CHANGELOG
66
72
  - Gemfile
67
73
  - LICENSE
@@ -94,17 +100,17 @@ require_paths:
94
100
  - lib
95
101
  required_ruby_version: !ruby/object:Gem::Requirement
96
102
  requirements:
97
- - - '>='
103
+ - - ">="
98
104
  - !ruby/object:Gem::Version
99
105
  version: '0'
100
106
  required_rubygems_version: !ruby/object:Gem::Requirement
101
107
  requirements:
102
- - - '>='
108
+ - - ">="
103
109
  - !ruby/object:Gem::Version
104
110
  version: '0'
105
111
  requirements: []
106
112
  rubyforge_project:
107
- rubygems_version: 2.0.3
113
+ rubygems_version: 2.2.2
108
114
  signing_key:
109
115
  specification_version: 4
110
116
  summary: An extension to the sidekiq message processing to track your jobs
@@ -116,3 +122,4 @@ test_files:
116
122
  - spec/lib/sidekiq-status_spec.rb
117
123
  - spec/spec_helper.rb
118
124
  - spec/support/test_jobs.rb
125
+ has_rdoc: