sidekiq-scheduler 0.4.1 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +23 -69
- data/bin/sidekiq-scheduler +4 -9
- data/lib/sidekiq-scheduler.rb +1 -3
- data/lib/sidekiq-scheduler/cli.rb +9 -5
- data/lib/sidekiq-scheduler/manager.rb +2 -57
- data/lib/sidekiq-scheduler/schedule.rb +6 -7
- data/lib/sidekiq-scheduler/version.rb +2 -2
- data/lib/sidekiq/scheduler.rb +11 -7
- data/lib/tasks/sidekiq-scheduler_tasks.rake +1 -1
- data/test/cli_test.rb +6 -1
- data/test/lib/sidekiq/scheduler_test.rb +97 -148
- data/test/schedule_test.rb +1 -5
- data/test/test_helper.rb +13 -9
- metadata +50 -54
- data/lib/sidekiq-scheduler/client.rb +0 -87
- data/lib/sidekiq-scheduler/worker.rb +0 -26
- data/test/client_test.rb +0 -136
- data/test/manager_test.rb +0 -65
- data/test/testing_test.rb +0 -38
data/test/schedule_test.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class ScheduleTest <
|
4
|
-
#class ScheduleManager
|
5
|
-
# extend SidekiqScheduler::ScheduleManager
|
6
|
-
#end
|
7
|
-
|
3
|
+
class ScheduleTest < Minitest::Test
|
8
4
|
|
9
5
|
describe 'SidekiqScheduler::Schedule' do
|
10
6
|
it 'schedule= sets the schedule' do
|
data/test/test_helper.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
-
require '
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
4
|
+
require 'minitest/autorun'
|
2
5
|
require 'minitest/pride'
|
3
6
|
require 'minitest/autorun'
|
4
7
|
require 'sidekiq-scheduler'
|
5
|
-
require 'mocha'
|
8
|
+
require 'mocha/setup'
|
6
9
|
require 'multi_json'
|
7
10
|
require 'mock_redis'
|
8
11
|
|
@@ -19,14 +22,15 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
|
19
22
|
|
20
23
|
require 'sidekiq/redis_connection'
|
21
24
|
|
22
|
-
#Setup redis mock to avoid having a dependency
|
23
|
-
# with redis server during tests
|
24
|
-
$redis = ConnectionPool.new(:timeout => 1, :size => 1) { MockRedis.new }
|
25
|
-
Sidekiq.redis = $redis
|
26
|
-
|
27
25
|
class MiniTest::Spec
|
28
26
|
before :each do
|
29
|
-
|
27
|
+
redis = MockRedis.new
|
28
|
+
client = Object.new
|
29
|
+
|
30
|
+
redis.stubs(:client).returns(client)
|
31
|
+
client.stubs(:location).returns('MockRedis')
|
32
|
+
|
33
|
+
Sidekiq::RedisConnection.stubs(:create).returns(ConnectionPool.new({}) { redis })
|
30
34
|
end
|
31
35
|
end
|
32
36
|
|
@@ -43,4 +47,4 @@ end
|
|
43
47
|
class SomeRealClass
|
44
48
|
include Sidekiq::Worker
|
45
49
|
sidekiq_options :queue => :some_real_queue
|
46
|
-
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,36 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-scheduler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: '0.6'
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Morton Jonuschat
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-04-03 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: sidekiq
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
version: 2.12.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
26
|
+
version: 2.12.0
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: redis
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ! '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ! '>='
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rufus-scheduler
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ~>
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,15 +48,27 @@ dependencies:
|
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ~>
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: multi_json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
62
69
|
- !ruby/object:Gem::Dependency
|
63
70
|
name: rake
|
64
71
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
72
|
requirements:
|
67
73
|
- - ! '>='
|
68
74
|
- !ruby/object:Gem::Version
|
@@ -70,7 +76,6 @@ dependencies:
|
|
70
76
|
type: :development
|
71
77
|
prerelease: false
|
72
78
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
79
|
requirements:
|
75
80
|
- - ! '>='
|
76
81
|
- !ruby/object:Gem::Version
|
@@ -78,7 +83,6 @@ dependencies:
|
|
78
83
|
- !ruby/object:Gem::Dependency
|
79
84
|
name: timecop
|
80
85
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
86
|
requirements:
|
83
87
|
- - ! '>='
|
84
88
|
- !ruby/object:Gem::Version
|
@@ -86,7 +90,6 @@ dependencies:
|
|
86
90
|
type: :development
|
87
91
|
prerelease: false
|
88
92
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
93
|
requirements:
|
91
94
|
- - ! '>='
|
92
95
|
- !ruby/object:Gem::Version
|
@@ -94,7 +97,6 @@ dependencies:
|
|
94
97
|
- !ruby/object:Gem::Dependency
|
95
98
|
name: mocha
|
96
99
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
100
|
requirements:
|
99
101
|
- - ! '>='
|
100
102
|
- !ruby/object:Gem::Version
|
@@ -102,7 +104,6 @@ dependencies:
|
|
102
104
|
type: :development
|
103
105
|
prerelease: false
|
104
106
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
107
|
requirements:
|
107
108
|
- - ! '>='
|
108
109
|
- !ruby/object:Gem::Version
|
@@ -110,7 +111,6 @@ dependencies:
|
|
110
111
|
- !ruby/object:Gem::Dependency
|
111
112
|
name: minitest
|
112
113
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
114
|
requirements:
|
115
115
|
- - ! '>='
|
116
116
|
- !ruby/object:Gem::Version
|
@@ -118,7 +118,6 @@ dependencies:
|
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
121
|
requirements:
|
123
122
|
- - ! '>='
|
124
123
|
- !ruby/object:Gem::Version
|
@@ -126,7 +125,6 @@ dependencies:
|
|
126
125
|
- !ruby/object:Gem::Dependency
|
127
126
|
name: mock_redis
|
128
127
|
requirement: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
128
|
requirements:
|
131
129
|
- - ! '>='
|
132
130
|
- !ruby/object:Gem::Version
|
@@ -134,7 +132,20 @@ dependencies:
|
|
134
132
|
type: :development
|
135
133
|
prerelease: false
|
136
134
|
version_requirements: !ruby/object:Gem::Requirement
|
137
|
-
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: simplecov
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ! '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
138
149
|
requirements:
|
139
150
|
- - ! '>='
|
140
151
|
- !ruby/object:Gem::Version
|
@@ -148,71 +159,56 @@ executables:
|
|
148
159
|
extensions: []
|
149
160
|
extra_rdoc_files: []
|
150
161
|
files:
|
162
|
+
- MIT-LICENSE
|
163
|
+
- README.md
|
164
|
+
- Rakefile
|
151
165
|
- bin/sidekiq-scheduler
|
152
|
-
- lib/sidekiq-scheduler
|
166
|
+
- lib/sidekiq-scheduler.rb
|
167
|
+
- lib/sidekiq-scheduler/capistrano.rb
|
153
168
|
- lib/sidekiq-scheduler/cli.rb
|
154
169
|
- lib/sidekiq-scheduler/manager.rb
|
155
|
-
- lib/sidekiq-scheduler/capistrano.rb
|
156
170
|
- lib/sidekiq-scheduler/schedule.rb
|
157
|
-
- lib/sidekiq-scheduler/worker.rb
|
158
|
-
- lib/sidekiq-scheduler/version.rb
|
159
171
|
- lib/sidekiq-scheduler/testing.rb
|
160
|
-
- lib/sidekiq-scheduler.rb
|
161
|
-
- lib/tasks/sidekiq-scheduler_tasks.rake
|
172
|
+
- lib/sidekiq-scheduler/version.rb
|
162
173
|
- lib/sidekiq/scheduler.rb
|
163
|
-
-
|
164
|
-
-
|
165
|
-
- README.md
|
166
|
-
- test/support/direct_worker.rb
|
167
|
-
- test/support/my_worker.rb
|
174
|
+
- lib/tasks/sidekiq-scheduler_tasks.rake
|
175
|
+
- test/cli_test.rb
|
168
176
|
- test/config.yml
|
169
|
-
- test/manager_test.rb
|
170
177
|
- test/fake_env.rb
|
171
|
-
- test/test_helper.rb
|
172
178
|
- test/lib/sidekiq/scheduler_test.rb
|
173
|
-
- test/cli_test.rb
|
174
|
-
- test/testing_test.rb
|
175
179
|
- test/schedule_test.rb
|
176
|
-
- test/
|
180
|
+
- test/support/direct_worker.rb
|
181
|
+
- test/support/my_worker.rb
|
182
|
+
- test/test_helper.rb
|
177
183
|
homepage: https://github.com/yabawock/sidekiq-scheduler
|
178
184
|
licenses: []
|
185
|
+
metadata: {}
|
179
186
|
post_install_message:
|
180
187
|
rdoc_options: []
|
181
188
|
require_paths:
|
182
189
|
- lib
|
183
190
|
required_ruby_version: !ruby/object:Gem::Requirement
|
184
|
-
none: false
|
185
191
|
requirements:
|
186
192
|
- - ! '>='
|
187
193
|
- !ruby/object:Gem::Version
|
188
194
|
version: '0'
|
189
|
-
segments:
|
190
|
-
- 0
|
191
|
-
hash: -363015005747774647
|
192
195
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
|
-
none: false
|
194
196
|
requirements:
|
195
197
|
- - ! '>='
|
196
198
|
- !ruby/object:Gem::Version
|
197
199
|
version: '0'
|
198
|
-
segments:
|
199
|
-
- 0
|
200
|
-
hash: -363015005747774647
|
201
200
|
requirements: []
|
202
201
|
rubyforge_project:
|
203
|
-
rubygems_version:
|
202
|
+
rubygems_version: 2.2.0
|
204
203
|
signing_key:
|
205
|
-
specification_version:
|
204
|
+
specification_version: 4
|
206
205
|
summary: Light weight job scheduling extension for Sidekiq
|
207
206
|
test_files:
|
208
|
-
- test/
|
207
|
+
- test/schedule_test.rb
|
209
208
|
- test/support/my_worker.rb
|
210
|
-
- test/
|
211
|
-
- test/manager_test.rb
|
212
|
-
- test/fake_env.rb
|
209
|
+
- test/support/direct_worker.rb
|
213
210
|
- test/test_helper.rb
|
214
211
|
- test/lib/sidekiq/scheduler_test.rb
|
212
|
+
- test/fake_env.rb
|
213
|
+
- test/config.yml
|
215
214
|
- test/cli_test.rb
|
216
|
-
- test/testing_test.rb
|
217
|
-
- test/schedule_test.rb
|
218
|
-
- test/client_test.rb
|
@@ -1,87 +0,0 @@
|
|
1
|
-
require 'sidekiq-scheduler/worker'
|
2
|
-
require 'sidekiq/client'
|
3
|
-
|
4
|
-
module SidekiqScheduler
|
5
|
-
module Client
|
6
|
-
# Example usage:
|
7
|
-
# Sidekiq::Client.delayed_push('my_queue', Time.now + 600, 'class' => MyWorker, 'args' => ['foo', 1, :bat => 'bar'])
|
8
|
-
def delayed_push(queue=nil, timestamp, item)
|
9
|
-
raise(ArgumentError, "Message must be a Hash of the form: { 'class' => SomeClass, 'args' => ['bob', 1, :foo => 'bar'] }") unless item.is_a?(Hash)
|
10
|
-
raise(ArgumentError, "Message must include a class and set of arguments: #{item.inspect}") if !item['class'] || !item['args']
|
11
|
-
|
12
|
-
timestamp = timestamp.to_i
|
13
|
-
|
14
|
-
item['queue'] = queue.to_s if queue
|
15
|
-
item['class'] = item['class'].to_s if !item['class'].is_a?(String)
|
16
|
-
|
17
|
-
# Add item to the list for this timestamp
|
18
|
-
Sidekiq.redis { |r| r.rpush("delayed:#{timestamp}", MultiJson.encode(item)) }
|
19
|
-
|
20
|
-
# Add timestamp to zset. Score and value are based on the timestamp
|
21
|
-
# as querying will be based on that
|
22
|
-
Sidekiq.redis { |r| r.zadd('delayed_queue_schedule', timestamp, timestamp) }
|
23
|
-
end
|
24
|
-
|
25
|
-
def remove_scheduler_queue(timestamp)
|
26
|
-
key = "delayed:#{timestamp}"
|
27
|
-
if 0 == Sidekiq.redis { |r| r.llen(key) }
|
28
|
-
Sidekiq.redis { |r| r.del(key) }
|
29
|
-
Sidekiq.redis { |r| r.zrem('delayed_queue_schedule', timestamp) }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# Example usage:
|
34
|
-
# Sidekiq::Client.remove_all_delayed(MyWorker, 'foo', 1, :bat => 'bar')
|
35
|
-
#
|
36
|
-
# Returns the number of jobs removed
|
37
|
-
#
|
38
|
-
# This method can be very expensive since it needs to scan
|
39
|
-
# through the delayed queues of all timestamps
|
40
|
-
def remove_all_delayed(klass, *args)
|
41
|
-
remove_all_delayed_from_queue(nil, klass, *args)
|
42
|
-
end
|
43
|
-
|
44
|
-
# Example usage:
|
45
|
-
# Sidekiq::Client.remove_all_delayed('foo', MyWorker, 'foo', 1, :bat => 'bar')
|
46
|
-
#
|
47
|
-
# Returns the number of jobs removed
|
48
|
-
#
|
49
|
-
# This method can be very expensive since it needs to scan
|
50
|
-
# through the delayed queues of all timestamps
|
51
|
-
def remove_all_delayed_from_queue(queue, klass, *args)
|
52
|
-
count = 0
|
53
|
-
item = {'class' => klass.to_s, 'args' => args}
|
54
|
-
item['queue'] = queue.to_s if queue
|
55
|
-
search = MultiJson.encode(item)
|
56
|
-
Array(Sidekiq.redis { |r| r.keys("delayed:*") }).each do |key|
|
57
|
-
count += Sidekiq.redis { |r| r.lrem(key, 0, search) }
|
58
|
-
end
|
59
|
-
count
|
60
|
-
end
|
61
|
-
|
62
|
-
# Example usage:
|
63
|
-
# Sidekiq::Client.remove_delayed(Time.now + 600, MyWorker, 'foo', 1, :bat => 'bar')
|
64
|
-
#
|
65
|
-
# Returns the number of jobs removed
|
66
|
-
def remove_delayed(timestamp, klass, *args)
|
67
|
-
remove_delayed_from_queue(nil, timestamp, klass, *args)
|
68
|
-
end
|
69
|
-
|
70
|
-
|
71
|
-
# Example usage:
|
72
|
-
# Sidekiq::Client.remove_delayed('foo', Time.now + 600, MyWorker, 'foo', 1, :bat => 'bar')
|
73
|
-
#
|
74
|
-
# Returns the number of jobs removed
|
75
|
-
def remove_delayed_from_queue(queue, timestamp, klass, *args)
|
76
|
-
timestamp = timestamp.to_i
|
77
|
-
item = {'class' => klass.to_s, 'args' => args}
|
78
|
-
item['queue'] = queue.to_s if queue
|
79
|
-
search = MultiJson.encode(item)
|
80
|
-
count = Sidekiq.redis { |r| r.lrem("delayed:#{timestamp}", 0, search) }
|
81
|
-
remove_scheduler_queue(timestamp)
|
82
|
-
count
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
Sidekiq::Client.send(:extend, SidekiqScheduler::Client)
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'sidekiq-scheduler/client'
|
2
|
-
require 'sidekiq/worker'
|
3
|
-
|
4
|
-
module SidekiqScheduler
|
5
|
-
module Worker
|
6
|
-
module ClassMethods
|
7
|
-
def perform_at(timestamp, *args)
|
8
|
-
Sidekiq::Client.delayed_push(timestamp, 'class' => self.name, 'args' => args)
|
9
|
-
end
|
10
|
-
|
11
|
-
def perform_in(seconds_from_now, *args)
|
12
|
-
Sidekiq::Client.delayed_push(Time.now + seconds_from_now, 'class' => self.name, 'args' => args)
|
13
|
-
end
|
14
|
-
|
15
|
-
def remove_delayed(*args)
|
16
|
-
Sidekiq::Client.remove_all_delayed(self.name, *args)
|
17
|
-
end
|
18
|
-
|
19
|
-
def remove_delayed_from_timestamp(timestamp, *args)
|
20
|
-
Sidekiq::Client.remove_delayed(timestamp, self.name, *args)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
Sidekiq::Worker::ClassMethods.send(:include, SidekiqScheduler::Worker::ClassMethods)
|
data/test/client_test.rb
DELETED
@@ -1,136 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'timecop'
|
3
|
-
|
4
|
-
class ClientTest < MiniTest::Unit::TestCase
|
5
|
-
describe 'with real redis' do
|
6
|
-
before do
|
7
|
-
Sidekiq.redis = Sidekiq::RedisConnection.create(:url => 'redis://localhost/15', :namespace => 'testy')
|
8
|
-
Sidekiq.redis {|c| c.flushdb }
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'removes scheduled messages and returns count' do
|
12
|
-
Sidekiq::Client.delayed_push(1331284491, 'class' => 'Foo', 'args' => [1, 2])
|
13
|
-
assert_equal 1, Sidekiq::Client.remove_all_delayed('Foo', 1, 2)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'removes scheduled messages for a queue and returns count' do
|
17
|
-
Sidekiq::Client.delayed_push('foo', 1331284491, 'class' => 'Foo', 'args' => [1, 2])
|
18
|
-
assert_equal 1, Sidekiq::Client.remove_all_delayed_from_queue('foo', 'Foo', 1, 2)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'removes only selected scheduled messages' do
|
22
|
-
Sidekiq::Client.delayed_push(1331284491, 'class' => 'Foo', 'args' => [1, 2])
|
23
|
-
Sidekiq::Client.delayed_push(1331284491, 'class' => 'Foo', 'args' => [3, 4])
|
24
|
-
Sidekiq::Client.delayed_push(1331284491, 'class' => 'Foo', 'args' => [3, 4])
|
25
|
-
Sidekiq::Client.delayed_push(1331284491, 'class' => 'Foo', 'args' => [5, 6])
|
26
|
-
assert_equal 0, Sidekiq::Client.remove_all_delayed('Foo')
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'removes messages in different timestamp queues' do
|
30
|
-
Sidekiq::Client.delayed_push(1331284491, 'class' => 'Foo', 'args' => [1, 2])
|
31
|
-
Sidekiq::Client.delayed_push(1331284492, 'class' => 'Foo', 'args' => [3, 4])
|
32
|
-
Sidekiq::Client.delayed_push(1331284493, 'class' => 'Foo', 'args' => [3, 4])
|
33
|
-
Sidekiq::Client.delayed_push(1331284493, 'class' => 'Foo', 'args' => [5, 6])
|
34
|
-
assert_equal 2, Sidekiq::Client.remove_all_delayed('Foo', 3, 4)
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'handles removed_delayed from a worker' do
|
38
|
-
Sidekiq::Client.delayed_push(1331284491, 'class' => 'MyWorker', 'args' => [1, 2])
|
39
|
-
Sidekiq::Client.delayed_push(1331284492, 'class' => 'MyWorker', 'args' => [3, 4])
|
40
|
-
Sidekiq::Client.delayed_push(1331284493, 'class' => 'MyWorker', 'args' => [3, 4])
|
41
|
-
Sidekiq::Client.delayed_push(1331284493, 'class' => 'MyWorker', 'args' => [5, 6])
|
42
|
-
assert_equal 2, MyWorker.remove_delayed(3, 4)
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'removes messages from specified timestamp' do
|
46
|
-
Sidekiq::Client.delayed_push(1331284491, 'class' => 'Foo', 'args' => [1, 2])
|
47
|
-
Sidekiq::Client.delayed_push(1331284492, 'class' => 'Foo', 'args' => [1, 2])
|
48
|
-
assert_equal 1, Sidekiq::Client.remove_delayed(1331284491, 'Foo', 1, 2)
|
49
|
-
assert_equal 1, Sidekiq.redis { |c| c.llen('delayed:1331284492') }
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'removes messages from a worker for a specified timestamp' do
|
53
|
-
Sidekiq::Client.delayed_push(1331284491, 'class' => 'MyWorker', 'args' => [1, 2])
|
54
|
-
Sidekiq::Client.delayed_push(1331284492, 'class' => 'MyWorker', 'args' => [1, 2])
|
55
|
-
assert_equal 1, MyWorker.remove_delayed_from_timestamp(1331284491, 1, 2)
|
56
|
-
assert_equal 1, Sidekiq.redis { |c| c.llen('delayed:1331284492') }
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'removes messages for a queue from specified timestamp' do
|
60
|
-
Sidekiq::Client.delayed_push('foo', 1331284491, 'class' => 'Foo', 'args' => [1, 2])
|
61
|
-
Sidekiq::Client.delayed_push('foo', 1331284492, 'class' => 'Foo', 'args' => [1, 2])
|
62
|
-
assert_equal 1, Sidekiq::Client.remove_delayed_from_queue('foo', 1331284491, 'Foo', 1, 2)
|
63
|
-
assert_equal 1, Sidekiq.redis { |c| c.llen('delayed:1331284492') }
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'removes nothing if no message is found' do
|
67
|
-
assert_equal 0, Sidekiq::Client.remove_delayed(1331284491, 'Foo', 3, 4)
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'removes only messages with matching arguments' do
|
71
|
-
Sidekiq::Client.delayed_push(1331284491, 'class' => 'Foo', 'args' => [1, 2])
|
72
|
-
Sidekiq::Client.delayed_push(1331284491, 'class' => 'Foo', 'args' => [3, 2])
|
73
|
-
assert_equal 0, Sidekiq::Client.remove_delayed(1331284491, 'Foo', 3, 4)
|
74
|
-
assert_equal 2, Sidekiq.redis { |c| c.llen('delayed:1331284491') }
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'removes empty scheduler queues' do
|
78
|
-
Sidekiq::Client.delayed_push(1331284491, 'class' => 'Foo', 'args' => [1, 2])
|
79
|
-
assert_equal 1, Sidekiq::Client.remove_delayed(1331284491, 'Foo', 1, 2)
|
80
|
-
assert !Sidekiq.redis { |c| c.exists('delayed:1331284491') }
|
81
|
-
assert_equal 0, Sidekiq.redis { |c| c.zcard('delayed_scheduler_queue') }
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe 'redis calls' do
|
86
|
-
before do
|
87
|
-
@redis = MiniTest::Mock.new
|
88
|
-
def @redis.multi; yield; end
|
89
|
-
def @redis.set(*); true; end
|
90
|
-
def @redis.sadd(*); true; end
|
91
|
-
def @redis.srem(*); true; end
|
92
|
-
def @redis.get(*); nil; end
|
93
|
-
def @redis.del(*); nil; end
|
94
|
-
def @redis.incrby(*); nil; end
|
95
|
-
def @redis.setex(*); nil; end
|
96
|
-
def @redis.expire(*); true; end
|
97
|
-
def @redis.with_connection; yield self; end
|
98
|
-
def @redis.with; yield self; end
|
99
|
-
Sidekiq.instance_variable_set(:@redis, @redis)
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'pushes delayed messages to redis' do
|
103
|
-
@redis.expect :rpush, 1, ['delayed:1661284491', String]
|
104
|
-
@redis.expect :zadd, 1, ['delayed_queue_schedule', 1661284491, 1661284491]
|
105
|
-
Sidekiq::Client.delayed_push('foo', 1661284491, 'class' => 'Foo', 'args' => [1, 2])
|
106
|
-
@redis.verify
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'removes empty scheduler queues' do
|
110
|
-
@redis.expect :llen, 0, ['delayed:1331284491']
|
111
|
-
@redis.expect :zrem, 1, ['delayed_queue_schedule', 1331284491]
|
112
|
-
Sidekiq::Client.remove_scheduler_queue(1331284491)
|
113
|
-
@redis.verify
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'handles perform_at' do
|
117
|
-
|
118
|
-
#@redis.expect :rpush, 1, ['delayed:1331284491', String]
|
119
|
-
@redis.expect :zadd, 1, ['schedule', "1331284491.0", String]
|
120
|
-
MyWorker.perform_at(1331284491, 1, 2)
|
121
|
-
|
122
|
-
@redis.verify
|
123
|
-
end
|
124
|
-
|
125
|
-
it 'handles perform_in' do
|
126
|
-
|
127
|
-
Timecop.freeze(Time.now) do
|
128
|
-
timestamp = Time.now + 30
|
129
|
-
#@redis.expect :rpush, 1, ["delayed:#{timestamp.to_i}", String]
|
130
|
-
@redis.expect :zadd, 1, ['schedule', "#{timestamp.to_f}", String]
|
131
|
-
MyWorker.perform_in(30, 1, 2)
|
132
|
-
@redis.verify
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|