rekiq 0.7.0 → 0.8.1

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: 5ab17f1066259e1b4fce0a5391f53892d24623f8
4
- data.tar.gz: 8e5c4948b2489f7da947a1b217f795f9fdf350b6
3
+ metadata.gz: 482599a4667b43c5690d7a4232e0ae3d87f2c4fd
4
+ data.tar.gz: 9964d52d551ed769dada46c3ab8427f77465c8ff
5
5
  SHA512:
6
- metadata.gz: 6753e66d5b3e4163949f5f53d2078d6d40c300ae626db977c0a4acc3729114a1726bffbfee2fa7e7806d29cc528e061ed4e0f7354799be1beaf3fa7b7451b276
7
- data.tar.gz: 919abea474e6f00c19ac3b78a9c9ba1bc84a8bf05dc7982faa55667a1090fa11cafd9b41b905325971b5880d226da0bda16da62efc3aaf9b7ee083173bff88d5
6
+ metadata.gz: 34104c582240196d8effd91b0ea5ae48f9d43beb0e7fba9ba5fe8db2e93b17f4269488a947967f5f0f7ebb8d3bf43801e5239db29d8e1ff2ee8033b73e6b0132
7
+ data.tar.gz: 71f5c7c77a0934bea52bfba4f0913e3ef86260b1ba657e0cf28cce45d29b9e8933ca1803b29768f36422e497436e5b83bd8bb2525fa85438feea242e15c2b3f2
data/README.md CHANGED
@@ -71,7 +71,7 @@ For our example we'll be using the gem [ice_cube](https://github.com/seejohnrun/
71
71
  # now just start your worker
72
72
  ExampleWorker.perform_recurringly(schedule, 'argument_1', 'argument_2')
73
73
 
74
- And that's it! Now the worker will run every friday as 2am.
74
+ And that's it! Now the worker will run every friday as 2am.
75
75
 
76
76
  You can use your own schedule object, configure worker to schedule before or
77
77
  after work is done, set a margin, and much more! So please feel free to check
@@ -79,7 +79,7 @@ after work is done, set a margin, and much more! So please feel free to check
79
79
 
80
80
  ## Contributing
81
81
 
82
- 1. Fork it ( https://github.com/[my-github-username]/rekiq/fork )
82
+ 1. Fork it ( https://github.com/junhanamaki/rekiq/fork )
83
83
  2. Create your feature branch (`git checkout -b my-new-feature`)
84
84
  3. Commit your changes (`git commit -am 'Add some feature'`)
85
85
  4. Push to the branch (`git push origin my-new-feature`)
data/example/test_app.rb CHANGED
@@ -9,7 +9,7 @@ require 'rekiq'
9
9
  class TestWorker1
10
10
  include Sidekiq::Worker
11
11
 
12
- sidekiq_options queue: "rekiq_test_worker", retry: false
12
+ sidekiq_options queue: "rekiq_test_worker", retry: 3
13
13
 
14
14
  def perform(arg1, arg2)
15
15
  puts "\n\nhello from TestWorker1, arg1 is #{arg1}, arg2 is #{arg2}" \
@@ -9,15 +9,19 @@ module Rekiq
9
9
  include ::Sidekiq::Util
10
10
 
11
11
  def call(worker, msg, queue)
12
- return yield unless msg['rq:job'] and msg['retry_count'].nil?
12
+ return yield unless msg.key?('rq:job')
13
13
 
14
14
  setup_vars(worker, msg, queue)
15
15
 
16
16
  if !@canceller_name.nil? and
17
17
  worker.send(@canceller_name, *@canceller_args)
18
- return logger.info 'worker canceled by rekiq_canceller'
18
+ return logger.info 'worker canceled by recurrence canceller'
19
19
  end
20
20
 
21
+ return yield unless msg.key?('rq:schdlr')
22
+
23
+ msg.delete('rq:schdlr')
24
+
21
25
  begin
22
26
  reschedule unless @job.schedule_post_work?
23
27
  yield
@@ -29,7 +33,7 @@ module Rekiq
29
33
  protected
30
34
 
31
35
  def setup_vars(worker, msg, queue)
32
- @canceller_name = worker.rekiq_canceller_name
36
+ @canceller_name = worker.recurrence_canceller_name
33
37
  @canceller_args = msg['rq:ca']
34
38
  @worker_name = worker.class.name
35
39
  @queue = queue
@@ -31,9 +31,10 @@ module Rekiq
31
31
  'args' => @args,
32
32
  'rq:job' => @job.to_array,
33
33
  'rq:at' => @work_time.to_f,
34
+ 'rq:schdlr' => nil
34
35
  }.tap do |hash|
35
36
  hash['rq:addon'] = @addon unless @addon.nil?
36
- hash['rq:ca'] = @canceller_args unless @canceller_args.nil?
37
+ hash['rq:ca'] = @canceller_args unless @canceller_args.nil?
37
38
  end
38
39
 
39
40
  Sidekiq::Client.push(client_args)
data/lib/rekiq/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rekiq
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.1"
3
3
  end
data/lib/rekiq/worker.rb CHANGED
@@ -6,20 +6,14 @@ module Rekiq
6
6
  module Worker
7
7
  class Configuration
8
8
  attr_accessor :shift, :schedule_post_work, :schedule_expired,
9
- :expiration_margin, :addon, :canceller_args
9
+ :expiration_margin, :addon, :recurrence_canceller_args
10
10
 
11
- def rekiq_canceller_args(*args)
12
- self.canceller_args = args
11
+ def recurrence_canceller_args(*args)
12
+ self.recurrence_canceller_args = args
13
13
  end
14
14
  end
15
15
 
16
16
  module ClassMethods
17
- attr_reader :canceller_name
18
-
19
- def rekiq_canceller(method_name)
20
- @canceller_name = method_name
21
- end
22
-
23
17
  def perform_recurringly(schedule, *args)
24
18
  @config = Configuration.new
25
19
  yield @config if block_given?
@@ -40,7 +34,7 @@ module Rekiq
40
34
 
41
35
  jid, work_time =
42
36
  Rekiq::Scheduler
43
- .new(name, queue, args, job, @config.addon, @config.canceller_args)
37
+ .new(name, queue, args, job, @config.addon, @config.recurrence_canceller_args)
44
38
  .schedule
45
39
 
46
40
  if jid.nil?
@@ -52,15 +46,20 @@ module Rekiq
52
46
  jid
53
47
  end
54
48
 
49
+ def recurrence_canceller_name
50
+ get_sidekiq_options['recurrence_canceller_name']
51
+ end
52
+
55
53
  protected
56
54
 
57
55
  def validate!
58
- unless canceller_name.nil? or
59
- self.method_defined?(canceller_name)
56
+ unless recurrence_canceller_name.nil? or
57
+ self.method_defined?(recurrence_canceller_name)
60
58
  raise CancellerMethodMissing,
61
- "rekiq_canceller method defined as #{canceller_name} " \
62
- 'but worker does not have a method with that name, either ' \
63
- 'remove rekiq_canceller or define missing method'
59
+ 'recurrence canceller method name defined as ' \
60
+ "#{recurrence_canceller_name}, but worker does not have " \
61
+ 'a method with that name, either remove definition or define ' \
62
+ 'missing method'
64
63
  end
65
64
  end
66
65
  end
@@ -78,8 +77,8 @@ module Sidekiq
78
77
  base.extend(Rekiq::Worker::ClassMethods)
79
78
  end
80
79
 
81
- def rekiq_canceller_name
82
- self.class.canceller_name
80
+ def recurrence_canceller_name
81
+ self.class.recurrence_canceller_name
83
82
  end
84
83
  end
85
84
  end
data/rekiq.gemspec CHANGED
@@ -8,8 +8,10 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Rekiq::VERSION
9
9
  spec.authors = ["junhanamaki"]
10
10
  spec.email = ["jun.hanamaki@gmail.com"]
11
- spec.summary = %q{recurring worker extension for sidekiq}
12
- spec.description = %q{}
11
+ spec.summary = %q{Recurring worker extension for Sidekiq}
12
+ spec.description = %q{Rekiq extends Sidekiq so that we can schedule
13
+ recurring workers, check homepage for
14
+ more details.}
13
15
  spec.homepage = "https://github.com/junhanamaki/rekiq"
14
16
  spec.license = "MIT"
15
17
 
@@ -1,8 +1,8 @@
1
1
  FactoryGirl.define do
2
2
  factory :configuration, class: Rekiq::Configuration do
3
- shift { [*-100..100].sample }
4
- schedule_post_work { [true, false].sample }
5
- expiration_margin { [*0..100].sample }
6
- schedule_expired { [true, false].sample }
3
+ shift [*-100..100].sample
4
+ schedule_post_work [true, false].sample
5
+ expiration_margin [*0..100].sample
6
+ schedule_expired [true, false].sample
7
7
  end
8
8
  end
@@ -3,13 +3,13 @@ require 'ice_cube'
3
3
  FactoryGirl.define do
4
4
  factory :job, class: Rekiq::Job do
5
5
  shift 0
6
- schedule { IceCube::Schedule.new(Time.now + 3600) }
6
+ schedule IceCube::Schedule.new(Time.now + 3600)
7
7
 
8
8
  trait :randomized_attributes do
9
- shift { [*0..100].sample }
10
- schedule_post_work { [nil, false, true].sample }
11
- schedule_expired { [nil, false, true].sample }
12
- expiration_margin { [*0..100].sample }
9
+ shift [*0..100].sample
10
+ schedule_post_work [nil, false, true].sample
11
+ schedule_expired [nil, false, true].sample
12
+ expiration_margin [*0..100].sample
13
13
  end
14
14
  end
15
15
  end
@@ -10,8 +10,8 @@ describe Rekiq::Middleware::WorkOverseer do
10
10
  class WorkOverseerCancelTestWorker
11
11
  include Sidekiq::Worker
12
12
 
13
- sidekiq_options queue: 'work_overseer_test_worker'
14
- rekiq_canceller :cancel
13
+ sidekiq_options queue: 'work_overseer_test_worker',
14
+ recurrence_canceller_name: :cancel
15
15
 
16
16
  def cancel(bool)
17
17
  bool
@@ -24,12 +24,15 @@ describe Rekiq::Middleware::WorkOverseer do
24
24
  let(:job) { build(:job, schedule: schedule) }
25
25
  let(:overseer) { Rekiq::Middleware::WorkOverseer.new }
26
26
 
27
- context 'worker does not have rekiq_canceller set' do
27
+ context 'worker does not have recurrence_canceller_name set' do
28
28
  let(:worker) { WorkOverseerTestWorker.new }
29
29
  let(:queue) { WorkOverseerTestWorker.get_sidekiq_options['queue'] }
30
30
 
31
- context 'msg with rq:job key (existing job)' do
32
- let(:msg) { { 'rq:job' => job.to_array, 'args' => args } }
31
+ context 'msg with rq:job key (existing job), ' \
32
+ 'with rq:schdlr key (value is irrelevant)' do
33
+ let(:msg) do
34
+ { 'rq:job' => job.to_array, 'args' => args, 'rq:schdlr' => nil }
35
+ end
33
36
 
34
37
  it 'yields once' do
35
38
  expect do |b|
@@ -42,6 +45,12 @@ describe Rekiq::Middleware::WorkOverseer do
42
45
 
43
46
  expect(WorkOverseerTestWorker.jobs.count).to eq(1)
44
47
  end
48
+
49
+ it 'removes key rq:schdlr from message after invocation' do
50
+ overseer.call(worker, msg, queue) {}
51
+
52
+ expect(msg.key?('rq:schdlr')).to eq(false)
53
+ end
45
54
  end
46
55
 
47
56
  context 'msg without rq:job key' do
@@ -54,9 +63,8 @@ describe Rekiq::Middleware::WorkOverseer do
54
63
  end
55
64
  end
56
65
 
57
- context 'msg with job retry info and rq:job (existing job)' do
58
- let(:msg) { { 'rq:job' => job.to_array, 'retry_count' => 0,
59
- 'args' => args } }
66
+ context 'msg without rq:schdlr and rq:job (existing job)' do
67
+ let(:msg) { { 'rq:job' => job.to_array, 'args' => args } }
60
68
 
61
69
  it 'yields once' do
62
70
  expect do |b|
@@ -64,7 +72,7 @@ describe Rekiq::Middleware::WorkOverseer do
64
72
  end.to yield_control.once
65
73
  end
66
74
 
67
- it 'does not schedule work' do
75
+ it 'does not schedule next work' do
68
76
  overseer.call(worker, msg, queue) {}
69
77
 
70
78
  expect(WorkOverseerTestWorker.jobs.count).to eq(0)
@@ -72,7 +80,7 @@ describe Rekiq::Middleware::WorkOverseer do
72
80
  end
73
81
  end
74
82
 
75
- context 'worker has rekiq_canceller method set' do
83
+ context 'worker has recurrence_canceller_name method set' do
76
84
  let(:worker) { WorkOverseerCancelTestWorker.new }
77
85
  let(:queue) { WorkOverseerCancelTestWorker.get_sidekiq_options['queue'] }
78
86
 
@@ -9,12 +9,12 @@ describe Rekiq::Worker do
9
9
 
10
10
  class CancellerUndefinedExampleWorker
11
11
  include Sidekiq::Worker
12
- rekiq_canceller :cancel
12
+ sidekiq_options recurrence_canceller_name: :cancel
13
13
  end
14
14
 
15
15
  class CancellerDefinedExampleWorker
16
16
  include Sidekiq::Worker
17
- rekiq_canceller :cancel
17
+ sidekiq_options recurrence_canceller_name: :cancel
18
18
 
19
19
  def cancel
20
20
  end
@@ -45,7 +45,8 @@ describe Rekiq::Worker do
45
45
  let(:time) { Time.now + 3600 }
46
46
  let(:schedule) { IceCube::Schedule.new(time) }
47
47
 
48
- context 'for worker with rekiq_canceller set with non defined method' do
48
+ context 'for worker with recurrence_canceller_name set with ' \
49
+ 'non defined method' do
49
50
  before do
50
51
  begin
51
52
  @jid =
@@ -65,7 +66,8 @@ describe Rekiq::Worker do
65
66
  end
66
67
  end
67
68
 
68
- context 'for worker with rekiq_canceller set with defined method' do
69
+ context 'for worker with recurrence_canceller_name set with ' \
70
+ 'defined method' do
69
71
  before do
70
72
  @jid = CancellerDefinedExampleWorker.perform_recurringly(schedule)
71
73
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rekiq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - junhanamaki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-21 00:00:00.000000000 Z
11
+ date: 2014-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,7 +122,10 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '3.2'
125
- description: ''
125
+ description: |-
126
+ Rekiq extends Sidekiq so that we can schedule
127
+ recurring workers, check homepage for
128
+ more details.
126
129
  email:
127
130
  - jun.hanamaki@gmail.com
128
131
  executables: []
@@ -183,7 +186,7 @@ rubyforge_project:
183
186
  rubygems_version: 2.2.2
184
187
  signing_key:
185
188
  specification_version: 4
186
- summary: recurring worker extension for sidekiq
189
+ summary: Recurring worker extension for Sidekiq
187
190
  test_files:
188
191
  - spec/factories/configuration.rb
189
192
  - spec/factories/job.rb