sidekiq_status 1.0.7 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63be21ef3fd839f7e92df3df5e368ff4a68e8bfc
4
- data.tar.gz: 52df11955cfcfdeb08834b17f4270bb59d999a72
3
+ metadata.gz: f4e3282b9acea7633ee8a90aed6fe8982bc17946
4
+ data.tar.gz: a480a2d256f63636be9ef162cfd791cea7ebaa32
5
5
  SHA512:
6
- metadata.gz: dda533578c80113a584638eed5bae730a2e2f24e69ea3f25d3e18c72aab79a8392d18a798c67af879174543df0de0c1ceb514c41eaa52fbdc4559105d2cd5383
7
- data.tar.gz: 442cebe74cc81e84510d2b6ca767553cdab771a8e93ff8176b54d5d60f6b78c5f016c3d8ebc0c15ddcd1bd0ea99e2e141d698265af0559bb022f9e0b3ede401f
6
+ metadata.gz: 61f4121815255d2d704cf262a9619a3ed0108a383e563188afbfb4cdd0367eb4acc32e6f14aed118c3d2eab0734046cf32571e703b3a097e0fc43debac79f1a6
7
+ data.tar.gz: dd87aa7efdb084aa718d0cd257c7b768d573fe6158b4f5d563172d01dd16f1608e06dccbd43c93f71de93fe95d727cf37727627b30c8188022d6e98f5a201d8e
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ sidekiq_status
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.2.4
data/.travis.yml CHANGED
@@ -1,21 +1,27 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.2
4
- - 1.9.3
5
- - 2.0.0
6
- # - jruby-19mode # JRuby in 1.9 mode
7
- # - rbx-19mode
3
+ - 2.1.10
4
+ - 2.2.4
5
+ - 2.3.0
6
+ - rbx-3.14
8
7
  env:
9
8
  global:
10
9
  - SHOW_SIDEKIQ=true
11
10
  matrix:
12
- - SIDEKIQ_VERSION="~>2.4.0"
13
- - SIDEKIQ_VERSION="~>2.6.5"
14
- - SIDEKIQ_VERSION="~>2.8.0"
15
- - SIDEKIQ_VERSION="~>2.10.0"
16
- - SIDEKIQ_VERSION="~>2.12.0"
17
- - SIDEKIQ_VERSION="~>2.13.0"
18
- - SIDEKIQ_VERSION="~>2.14.0"
19
- - SIDEKIQ_VERSION="~>2.15.0"
20
- - SIDEKIQ_VERSION="~>2.16.0"
11
+ - SIDEKIQ_VERSION="~>4.1.0"
12
+ - SIDEKIQ_VERSION="~>4.0.2"
13
+ - SIDEKIQ_VERSION="~>3.5.4"
14
+ - SIDEKIQ_VERSION="~>3.4.2"
15
+ - SIDEKIQ_VERSION="~>3.3.4"
16
+
17
+ before_install:
18
+ - sudo apt-get -qq update
19
+ - sudo apt-get install libgmp3-dev
20
+ - gem update --system
21
+ - gem update bundler
22
+ - gem --version
23
+ - bundle --version
24
+
21
25
  script: bundle exec rake
26
+ services:
27
+ - redis-server
data/README.md CHANGED
@@ -147,6 +147,17 @@ and clean status containers.
147
147
 
148
148
  ## Changelog
149
149
 
150
+ ### 1.1.0
151
+
152
+ * Support for sidekiq 4.1, 4.0, 3.5, 3.4
153
+ * No more replacement of original job arguments with generated unique jid.
154
+ This is not needed anymore as Sidekiq started to do it.
155
+ This change should make integration with other middlewares easier.
156
+ * Dropped support for sidekiq versions older than 3.3
157
+ * Dropped support for ruby 1.9.x, 2.0.x
158
+ * Experimental support for Rubinius
159
+
160
+
150
161
  ### 1.0.7
151
162
 
152
163
  * Sidekiq 2.16 support
@@ -2,7 +2,7 @@
2
2
 
3
3
  module SidekiqStatus
4
4
  class ClientMiddleware
5
- def call(worker, item, queue)
5
+ def call(worker, item, queue, redis_pool = nil)
6
6
  worker = worker.constantize if worker.is_a?(String)
7
7
  return yield unless worker < SidekiqStatus::Worker
8
8
 
@@ -23,7 +23,6 @@ module SidekiqStatus
23
23
 
24
24
  jid = item['jid']
25
25
  args = item['args']
26
- item['args'] = [jid]
27
26
 
28
27
  SidekiqStatus::Container.create(
29
28
  'jid' => jid,
@@ -156,7 +156,7 @@ module SidekiqStatus
156
156
  # @param [Array<#to_s>] jids a list of job identifiers to load data for
157
157
  # @return [Hash{String => Hash}] A hash of job-id to deserialized data pairs
158
158
  def self.load_data_multi(jids)
159
- keys = jids.map { |jid| status_key(jid) }
159
+ keys = jids.map(&method(:status_key))
160
160
 
161
161
  return {} if keys.empty?
162
162
 
@@ -260,6 +260,8 @@ module SidekiqStatus
260
260
  # @return [Integer] Job progress in percents (reported solely by {SidekiqStatus::Worker job})
261
261
  def pct_complete
262
262
  (at.to_f / total * 100).round
263
+ rescue FloatDomainError, ZeroDivisionError
264
+ 0
263
265
  end
264
266
 
265
267
  # @param [Fixnum] at Report the progress of a job which is tracked by the current {SidekiqStatus::Container}
@@ -1,5 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module SidekiqStatus
3
3
  # SidekiqStatus version
4
- VERSION = "1.0.7"
4
+ VERSION = "1.1.0"
5
5
  end
@@ -14,13 +14,13 @@ module SidekiqStatus
14
14
  end
15
15
 
16
16
  module Prepending
17
- def perform(jid)
17
+ def perform(*args)
18
18
  @status_container = SidekiqStatus::Container.load(jid)
19
19
 
20
20
  begin
21
21
  catch(:killed) do
22
22
  set_status('working')
23
- super(*@status_container.args)
23
+ super(*args)
24
24
  set_status('complete')
25
25
  end
26
26
  rescue Exception => exc
@@ -16,10 +16,11 @@ Gem::Specification.new do |gem|
16
16
  gem.require_paths = ["lib"]
17
17
  gem.version = SidekiqStatus::VERSION
18
18
 
19
- gem.add_runtime_dependency("sidekiq", ">= 2.4", "< 2.17")
19
+ gem.add_runtime_dependency("sidekiq", ">= 3.3", "< 4.2")
20
20
 
21
21
  gem.add_development_dependency("activesupport")
22
- gem.add_development_dependency("rspec")
22
+ gem.add_development_dependency("rspec", '>= 3.4.0')
23
+ gem.add_development_dependency("rspec-its")
23
24
  gem.add_development_dependency("simplecov")
24
25
  gem.add_development_dependency("rake")
25
26
  gem.add_development_dependency("timecop")
@@ -5,7 +5,7 @@ describe SidekiqStatus::ClientMiddleware do
5
5
  describe "cryo28/sidekiq_status#11 regression" do
6
6
  describe "#call" do
7
7
  before do
8
- SidekiqStatus::Container.should_receive(:create).with(hash_including('worker' => 'TestWorker1'))
8
+ expect(SidekiqStatus::Container).to receive(:create).with(hash_including('worker' => 'TestWorker1'))
9
9
  end
10
10
 
11
11
  it "accepts a worker class" do
@@ -21,7 +21,7 @@ describe SidekiqStatus::ClientMiddleware do
21
21
  end
22
22
 
23
23
  it "does not create container for scheduled job" do
24
- SidekiqStatus::Container.should_not_receive(:create)
24
+ expect(SidekiqStatus::Container).to_not receive(:create)
25
25
 
26
26
  subject.call("TestWorker1", { "at" => Time.now }, nil) do
27
27
  end
@@ -91,7 +91,7 @@ describe SidekiqStatus::Container do
91
91
  end
92
92
 
93
93
  specify ".create" do
94
- SecureRandom.should_receive(:hex).with(12).and_return(jid)
94
+ expect(SecureRandom).to receive(:hex).with(12).and_return(jid)
95
95
  args = ['arg1', 'arg2', {arg3: 'val3'}]
96
96
 
97
97
  container = described_class.create('args' => args)
@@ -102,7 +102,7 @@ describe SidekiqStatus::Container do
102
102
  test_container(container, described_class::DEFAULTS.reject{|k, v| k == 'args' }, jid)
103
103
 
104
104
  Sidekiq.redis do |conn|
105
- conn.exists(status_key).should be_true
105
+ conn.exists(status_key).should be true
106
106
  end
107
107
  end
108
108
 
@@ -112,7 +112,7 @@ describe SidekiqStatus::Container do
112
112
  end
113
113
 
114
114
  it "loads a container from the redis key" do
115
- json = MultiJson.dump(sample_json_hash)
115
+ json = Sidekiq.dump_json(sample_json_hash)
116
116
  Sidekiq.redis { |conn| conn.set(status_key, json) }
117
117
 
118
118
  container = described_class.load(jid)
@@ -128,7 +128,7 @@ describe SidekiqStatus::Container do
128
128
  )
129
129
  end
130
130
 
131
- json = MultiJson.dump(sample_json_hash)
131
+ json = Sidekiq.dump_json(sample_json_hash)
132
132
  Sidekiq.redis { |conn| conn.set(status_key, json) }
133
133
  described_class.load(jid)
134
134
 
@@ -151,7 +151,7 @@ describe SidekiqStatus::Container do
151
151
  described_class.new(jid, hash).save
152
152
 
153
153
  result = Sidekiq.redis{ |conn| conn.get(status_key) }
154
- result = MultiJson.load(result)
154
+ result = Sidekiq.load_json(result)
155
155
 
156
156
  result.should == hash.merge('last_updated_at' => Time.now.to_i)
157
157
 
@@ -168,14 +168,14 @@ describe SidekiqStatus::Container do
168
168
  container.delete
169
169
 
170
170
  Sidekiq.redis do |conn|
171
- conn.exists(status_key).should be_false
171
+ conn.exists(status_key).should be false
172
172
  conn.zscore(described_class.kill_key, jid).should be_nil
173
173
  end
174
174
  end
175
175
 
176
176
  specify "#request_kill, #should_kill?, #killable?" do
177
177
  container = described_class.new(jid)
178
- container.kill_requested?.should be_false
178
+ container.kill_requested?.should be_falsey
179
179
  container.should be_killable
180
180
 
181
181
  Sidekiq.redis do |conn|
@@ -220,8 +220,17 @@ describe SidekiqStatus::Container do
220
220
  container.at = 5
221
221
  container.total = 200
222
222
  container.pct_complete.should == 3 # 2.5.round(0) => 3
223
+
224
+ container.at = Float::INFINITY
225
+ container.pct_complete.should == 0 # FloatDomainError
226
+
227
+ container.at = 5
228
+ container.total = 0
229
+ container.pct_complete.should == 0 # ZeroDivisionError
223
230
  end
224
231
 
232
+
233
+
225
234
  context "setters" do
226
235
  let(:container) { described_class.new(jid) }
227
236
 
@@ -302,12 +311,12 @@ describe SidekiqStatus::Container do
302
311
  context "status is #{status_name1}" do
303
312
  subject{ described_class.create().tap{|c| c.status = status_name1} }
304
313
 
305
- its("#{status_name1}?") { should be_true }
314
+ its("#{status_name1}?") { should be true }
306
315
 
307
316
  (described_class::STATUS_NAMES - [status_name1]).each do |status_name2|
308
- its("#{status_name2}?") { should be_false }
317
+ its("#{status_name2}?") { should be false }
309
318
  end
310
319
  end
311
320
  end
312
321
  end
313
- end
322
+ end
data/spec/spec_helper.rb CHANGED
@@ -13,6 +13,7 @@ end
13
13
  require 'coveralls'
14
14
  Coveralls.wear!
15
15
 
16
+ require 'rspec/its'
16
17
  require 'sidekiq_status'
17
18
  require 'sidekiq/util'
18
19
 
@@ -24,6 +25,10 @@ Sidekiq.logger.level = Logger::ERROR
24
25
  require GEM_ROOT.join('spec/dummy/boot.rb')
25
26
 
26
27
  RSpec.configure do |c|
28
+ c.expect_with :rspec do |expectations|
29
+ expectations.syntax = [:should, :expect]
30
+ end
31
+
27
32
  c.before do
28
33
  Sidekiq.redis{ |conn| conn.flushdb }
29
34
  end
data/spec/worker_spec.rb CHANGED
@@ -26,10 +26,11 @@ describe Sidekiq::Worker do
26
26
  describe "#perform (Worker context)" do
27
27
  let(:worker) { SomeWorker.new }
28
28
 
29
- it "receives jid as parameters, loads container and runs original perform with enqueued args" do
30
- worker.should_receive(:some_method).with(*args)
29
+ it "loads container using @jid and runs original perform" do
30
+ expect(worker).to receive(:some_method).with(*args)
31
31
  jid = SomeWorker.perform_async(*args)
32
- worker.perform(jid)
32
+ worker.jid = jid.freeze
33
+ worker.perform(*args)
33
34
  end
34
35
 
35
36
  it "changes status to working" do
@@ -42,18 +43,20 @@ describe Sidekiq::Worker do
42
43
  end)
43
44
 
44
45
  jid = SomeWorker.perform_async(*args)
45
- worker.perform(jid)
46
+ worker.jid = jid.freeze
47
+ worker.perform(*args)
46
48
 
47
- has_been_run.should be_true
49
+ has_been_run.should be true
48
50
  worker.status_container.reload.status.should == 'complete'
49
51
  end
50
52
 
51
53
  it "intercepts failures and set status to 'failed' then re-raises the exception" do
52
54
  exc = RuntimeError.new('Some error')
53
- worker.stub(:some_method).and_raise(exc)
55
+ allow(worker).to receive(:some_method).and_raise(exc)
54
56
 
55
57
  jid = SomeWorker.perform_async(*args)
56
- expect{ worker.perform(jid) }.to raise_exception{ |error| error.object_id.should == exc.object_id }
58
+ worker.jid = jid.freeze
59
+ expect{ worker.perform(*args) }.to raise_exception{ |error| error.object_id.should == exc.object_id }
57
60
 
58
61
  container = SidekiqStatus::Container.load(jid)
59
62
  container.status.should == 'failed'
@@ -61,7 +64,8 @@ describe Sidekiq::Worker do
61
64
 
62
65
  it "sets status to 'complete' if finishes without errors" do
63
66
  jid = SomeWorker.perform_async(*args)
64
- worker.perform(jid)
67
+ worker.jid = jid.freeze
68
+ worker.perform(*args)
65
69
 
66
70
  container = SidekiqStatus::Container.load(jid)
67
71
  container.status.should == 'complete'
@@ -69,10 +73,12 @@ describe Sidekiq::Worker do
69
73
 
70
74
  it "handles kill requests if kill requested before job execution" do
71
75
  jid = SomeWorker.perform_async(*args)
76
+ worker.jid = jid.freeze
77
+
72
78
  container = SidekiqStatus::Container.load(jid)
73
79
  container.request_kill
74
80
 
75
- worker.perform(jid)
81
+ worker.perform(*args)
76
82
 
77
83
  container.reload
78
84
  container.status.should == 'killed'
@@ -80,6 +86,8 @@ describe Sidekiq::Worker do
80
86
 
81
87
  it "handles kill requests if kill requested amid job execution" do
82
88
  jid = SomeWorker.perform_async(*args)
89
+ worker.jid = jid.freeze
90
+
83
91
  container = SidekiqStatus::Container.load(jid)
84
92
  container.status.should == 'waiting'
85
93
 
@@ -117,6 +125,8 @@ describe Sidekiq::Worker do
117
125
 
118
126
  it "allows to set at, total and customer payload from the worker" do
119
127
  jid = SomeWorker.perform_async(*args)
128
+ worker.jid = jid.freeze
129
+
120
130
  container = SidekiqStatus::Container.load(jid)
121
131
 
122
132
  lets_stop = false
metadata CHANGED
@@ -1,131 +1,145 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq_status
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Ignatyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-11 00:00:00.000000000 Z
11
+ date: 2016-04-13 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
- version: '2.4'
20
- - - <
19
+ version: '3.3'
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '2.17'
22
+ version: '4.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - '>='
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '2.4'
30
- - - <
29
+ version: '3.3'
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '2.17'
32
+ version: '4.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: activesupport
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - '>='
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
40
  type: :development
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - '>='
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - '>='
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 3.4.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 3.4.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec-its
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
52
66
  - !ruby/object:Gem::Version
53
67
  version: '0'
54
68
  type: :development
55
69
  prerelease: false
56
70
  version_requirements: !ruby/object:Gem::Requirement
57
71
  requirements:
58
- - - '>='
72
+ - - ">="
59
73
  - !ruby/object:Gem::Version
60
74
  version: '0'
61
75
  - !ruby/object:Gem::Dependency
62
76
  name: simplecov
63
77
  requirement: !ruby/object:Gem::Requirement
64
78
  requirements:
65
- - - '>='
79
+ - - ">="
66
80
  - !ruby/object:Gem::Version
67
81
  version: '0'
68
82
  type: :development
69
83
  prerelease: false
70
84
  version_requirements: !ruby/object:Gem::Requirement
71
85
  requirements:
72
- - - '>='
86
+ - - ">="
73
87
  - !ruby/object:Gem::Version
74
88
  version: '0'
75
89
  - !ruby/object:Gem::Dependency
76
90
  name: rake
77
91
  requirement: !ruby/object:Gem::Requirement
78
92
  requirements:
79
- - - '>='
93
+ - - ">="
80
94
  - !ruby/object:Gem::Version
81
95
  version: '0'
82
96
  type: :development
83
97
  prerelease: false
84
98
  version_requirements: !ruby/object:Gem::Requirement
85
99
  requirements:
86
- - - '>='
100
+ - - ">="
87
101
  - !ruby/object:Gem::Version
88
102
  version: '0'
89
103
  - !ruby/object:Gem::Dependency
90
104
  name: timecop
91
105
  requirement: !ruby/object:Gem::Requirement
92
106
  requirements:
93
- - - '>='
107
+ - - ">="
94
108
  - !ruby/object:Gem::Version
95
109
  version: '0'
96
110
  type: :development
97
111
  prerelease: false
98
112
  version_requirements: !ruby/object:Gem::Requirement
99
113
  requirements:
100
- - - '>='
114
+ - - ">="
101
115
  - !ruby/object:Gem::Version
102
116
  version: '0'
103
117
  - !ruby/object:Gem::Dependency
104
118
  name: yard
105
119
  requirement: !ruby/object:Gem::Requirement
106
120
  requirements:
107
- - - '>='
121
+ - - ">="
108
122
  - !ruby/object:Gem::Version
109
123
  version: '0'
110
124
  type: :development
111
125
  prerelease: false
112
126
  version_requirements: !ruby/object:Gem::Requirement
113
127
  requirements:
114
- - - '>='
128
+ - - ">="
115
129
  - !ruby/object:Gem::Version
116
130
  version: '0'
117
131
  - !ruby/object:Gem::Dependency
118
132
  name: maruku
119
133
  requirement: !ruby/object:Gem::Requirement
120
134
  requirements:
121
- - - '>='
135
+ - - ">="
122
136
  - !ruby/object:Gem::Version
123
137
  version: '0'
124
138
  type: :development
125
139
  prerelease: false
126
140
  version_requirements: !ruby/object:Gem::Requirement
127
141
  requirements:
128
- - - '>='
142
+ - - ">="
129
143
  - !ruby/object:Gem::Version
130
144
  version: '0'
131
145
  description: Job status tracking extension for Sidekiq
@@ -135,11 +149,12 @@ executables: []
135
149
  extensions: []
136
150
  extra_rdoc_files: []
137
151
  files:
138
- - .gitignore
139
- - .rspec
140
- - .rvmrc
141
- - .travis.yml
142
- - .yardopts
152
+ - ".gitignore"
153
+ - ".rspec"
154
+ - ".ruby-gemset"
155
+ - ".ruby-version"
156
+ - ".travis.yml"
157
+ - ".yardopts"
143
158
  - Gemfile
144
159
  - LICENSE
145
160
  - README.md
@@ -172,17 +187,17 @@ require_paths:
172
187
  - lib
173
188
  required_ruby_version: !ruby/object:Gem::Requirement
174
189
  requirements:
175
- - - '>='
190
+ - - ">="
176
191
  - !ruby/object:Gem::Version
177
192
  version: '0'
178
193
  required_rubygems_version: !ruby/object:Gem::Requirement
179
194
  requirements:
180
- - - '>='
195
+ - - ">="
181
196
  - !ruby/object:Gem::Version
182
197
  version: '0'
183
198
  requirements: []
184
199
  rubyforge_project:
185
- rubygems_version: 2.1.10
200
+ rubygems_version: 2.4.8
186
201
  signing_key:
187
202
  specification_version: 4
188
203
  summary: A Sidekiq extension to track job execution statuses and return job results
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use 2.0.0-p247@sidekiq_status --create