rekiq 0.9.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -45,8 +45,7 @@ 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_cancel_method set with ' \
49
- 'non defined method' do
48
+ context 'for worker with rekiq_cancel_method set with non defined method' do
50
49
  before do
51
50
  begin
52
51
  @jid =
@@ -66,8 +65,7 @@ describe Rekiq::Worker do
66
65
  end
67
66
  end
68
67
 
69
- context 'for worker with rekiq_cancel_method set with ' \
70
- 'defined method' do
68
+ context 'for worker with rekiq_cancel_method set with defined method' do
71
69
  before do
72
70
  @jid = RekiqCancelMethodDefinedExampleWorker.perform_recurringly(schedule)
73
71
  end
@@ -87,7 +85,7 @@ describe Rekiq::Worker do
87
85
  end
88
86
 
89
87
  it 'schedules worker for one hour from now' do
90
- expect(RekiqCancelMethodDefinedExampleWorker.jobs[0]['at']).to eq(time.to_f)
88
+ expect(RekiqCancelMethodDefinedExampleWorker.jobs[0]['rq:at']).to eq(time.to_f)
91
89
  end
92
90
  end
93
91
 
@@ -105,7 +103,7 @@ describe Rekiq::Worker do
105
103
  end
106
104
 
107
105
  it 'schedules worker for one hour from now' do
108
- expect(ExampleWorker.jobs[0]['at']).to eq(time.to_f)
106
+ expect(ExampleWorker.jobs[0]['rq:at']).to eq(time.to_f)
109
107
  end
110
108
  end
111
109
 
@@ -113,8 +111,8 @@ describe Rekiq::Worker do
113
111
  let(:rekiq_cancel_args) { ['args1', 'args2'] }
114
112
  before do
115
113
  @jid = ExampleWorker.perform_recurringly(schedule) do |config|
116
- config.rekiq_cancel_args *rekiq_cancel_args
117
- end
114
+ config.rekiq_cancel_args *rekiq_cancel_args
115
+ end
118
116
  end
119
117
 
120
118
  it 'returns created job id' do
@@ -130,38 +128,14 @@ describe Rekiq::Worker do
130
128
  ExampleWorker.perform_recurringly(schedule, &b)
131
129
  end.to yield_control.once
132
130
  end
133
-
134
- it 'creates key rq:ca in job hash' do
135
- expect(ExampleWorker.jobs[0].key?('rq:ca')).to eq(true)
136
- end
137
-
138
- describe 'value under rq:ca key in job hash' do
139
- let(:value) { ExampleWorker.jobs[0]['rq:ca'] }
140
-
141
- it 'is an array' do
142
- expect(value.class).to eq(Array)
143
- end
144
-
145
- it 'has count equal to number of rekiq_cancel_args' do
146
- expect(value.count).to eq(rekiq_cancel_args.count)
147
- end
148
-
149
- it 'has first element equal to first arg in rekiq_cancel_args' do
150
- expect(value[0]).to eq(rekiq_cancel_args[0])
151
- end
152
-
153
- it 'has second element equal to second arg in rekiq_cancel_args' do
154
- expect(value[1]).to eq(rekiq_cancel_args[1])
155
- end
156
- end
157
131
  end
158
132
 
159
- context 'shift set to minus 5 minutes' do
160
- let(:shift) { -5 * 60 }
133
+ context 'work_time_shift set to minus 5 minutes' do
134
+ let(:work_time_shift) { -5 * 60 }
161
135
  before do
162
136
  @jid = ExampleWorker.perform_recurringly(schedule) do |config|
163
- config.shift = shift
164
- end
137
+ config.work_time_shift = work_time_shift
138
+ end
165
139
  end
166
140
 
167
141
  it 'returns created job id' do
@@ -178,14 +152,8 @@ describe Rekiq::Worker do
178
152
  end.to yield_control.once
179
153
  end
180
154
 
181
- it 'sets shift in position 1 of array under key rq:job' do
182
- array = ExampleWorker.jobs[0]['rq:job']
183
-
184
- expect(array[1]).to eq(shift)
185
- end
186
-
187
155
  it 'schedules worker for one hour minus 5 minutes from now' do
188
- expect(ExampleWorker.jobs[0]['at']).to eq(time.to_f + shift)
156
+ expect(ExampleWorker.jobs[0]['rq:at']).to eq(time.to_f + work_time_shift)
189
157
  end
190
158
  end
191
159
  end
data/spec/spec_helper.rb CHANGED
@@ -9,7 +9,6 @@ else
9
9
  end
10
10
 
11
11
  require 'factory_girl'
12
- require 'pry'
13
12
  require 'sidekiq'
14
13
  require 'sidekiq/testing'
15
14
  require 'rekiq'
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.9.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - junhanamaki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-24 00:00:00.000000000 Z
11
+ date: 2014-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '4.4'
83
- - !ruby/object:Gem::Dependency
84
- name: jazz_hands
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '0.5'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '0.5'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: ice_cube
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -144,8 +130,8 @@ files:
144
130
  - example/test_app.rb
145
131
  - lib/rekiq.rb
146
132
  - lib/rekiq/configuration.rb
133
+ - lib/rekiq/contract.rb
147
134
  - lib/rekiq/exceptions.rb
148
- - lib/rekiq/job.rb
149
135
  - lib/rekiq/middleware/utils.rb
150
136
  - lib/rekiq/middleware/work_overseer.rb
151
137
  - lib/rekiq/scheduler.rb
@@ -154,9 +140,9 @@ files:
154
140
  - lib/rekiq/worker.rb
155
141
  - rekiq.gemspec
156
142
  - spec/factories/configuration.rb
157
- - spec/factories/job.rb
143
+ - spec/factories/contract.rb
158
144
  - spec/rekiq/configuration_spec.rb
159
- - spec/rekiq/job_spec.rb
145
+ - spec/rekiq/contract_spec.rb
160
146
  - spec/rekiq/middleware/utils_spec.rb
161
147
  - spec/rekiq/middleware/work_overseer_spec.rb
162
148
  - spec/rekiq/scheduler_spec.rb
@@ -188,9 +174,9 @@ specification_version: 4
188
174
  summary: Recurring worker extension for Sidekiq
189
175
  test_files:
190
176
  - spec/factories/configuration.rb
191
- - spec/factories/job.rb
177
+ - spec/factories/contract.rb
192
178
  - spec/rekiq/configuration_spec.rb
193
- - spec/rekiq/job_spec.rb
179
+ - spec/rekiq/contract_spec.rb
194
180
  - spec/rekiq/middleware/utils_spec.rb
195
181
  - spec/rekiq/middleware/work_overseer_spec.rb
196
182
  - spec/rekiq/scheduler_spec.rb
data/lib/rekiq/job.rb DELETED
@@ -1,110 +0,0 @@
1
- require 'rekiq/validator'
2
- require 'rekiq/configuration'
3
-
4
- module Rekiq
5
- class Job
6
- include Validator
7
-
8
- attr_accessor :schedule, :shift, :schedule_post_work, :schedule_expired,
9
- :expiration_margin
10
-
11
- validate :schedule, :schedule
12
- validate :shift, :numeric, allow_nil: true
13
- validate :schedule_post_work, :bool, allow_nil: true
14
- validate :schedule_expired, :numeric, allow_nil: true
15
- validate :expiration_margin, :bool, allow_nil: true
16
-
17
- class << self
18
- def from_array(array)
19
- new \
20
- 'schedule' => Marshal.load(array[0].encode('ISO-8859-1')),
21
- 'shift' => array[1],
22
- 'schedule_post_work' => array[2],
23
- 'schedule_expired' => array[3],
24
- 'expiration_margin' => array[4]
25
- end
26
- end
27
-
28
- def initialize(attributes = {})
29
- self.schedule = attributes['schedule']
30
- self.shift = attributes['shift']
31
- self.schedule_post_work = attributes['schedule_post_work']
32
- self.schedule_expired = attributes['schedule_expired']
33
- self.expiration_margin = attributes['expiration_margin']
34
- end
35
-
36
- def to_array
37
- [
38
- Marshal.dump(schedule).force_encoding('ISO-8859-1').encode('UTF-8'),
39
- shift,
40
- schedule_post_work,
41
- schedule_expired,
42
- expiration_margin
43
- ]
44
- end
45
-
46
- def next_work_time(from = Time.now)
47
- from_with_shift = shift_val > 0 ? from - shift_val : from
48
-
49
- search_next_work_time(from_with_shift)
50
- end
51
-
52
- def next_work_time_from_work_time(from)
53
- from_with_shift = from - shift_val
54
-
55
- search_next_work_time(from_with_shift)
56
- end
57
-
58
- def schedule_post_work?
59
- unless schedule_post_work.nil?
60
- schedule_post_work
61
- else
62
- Rekiq.configuration.schedule_post_work
63
- end
64
- end
65
-
66
- private
67
-
68
- def search_next_work_time(from)
69
- if schedule_expired?
70
- from = schedule.next_occurrence(from)
71
- work_time = from.nil? ? nil : from + shift_val
72
- else
73
- begin
74
- from = schedule.next_occurrence(from)
75
- work_time = from.nil? ? nil : from + shift_val
76
- end until work_time.nil? || work_time > expiration_time
77
- end
78
-
79
- work_time
80
- end
81
-
82
- def schedule_expired?
83
- unless schedule_expired.nil?
84
- schedule_expired
85
- else
86
- Rekiq.configuration.schedule_expired
87
- end
88
- end
89
-
90
- def expiration_margin_val
91
- unless expiration_margin.nil?
92
- expiration_margin
93
- else
94
- Rekiq.configuration.expiration_margin
95
- end
96
- end
97
-
98
- def shift_val
99
- unless shift.nil?
100
- shift
101
- else
102
- Rekiq.configuration.shift
103
- end
104
- end
105
-
106
- def expiration_time
107
- Time.now - expiration_margin_val
108
- end
109
- end
110
- end
@@ -1,15 +0,0 @@
1
- require 'ice_cube'
2
-
3
- FactoryGirl.define do
4
- factory :job, class: Rekiq::Job do
5
- shift 0
6
- schedule IceCube::Schedule.new(Time.now + 3600)
7
-
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
13
- end
14
- end
15
- end