sidekiq-scheduler 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/sidekiq-scheduler +2 -2
- data/lib/sidekiq-scheduler.rb +1 -2
- data/lib/sidekiq-scheduler/client.rb +8 -8
- data/lib/sidekiq-scheduler/manager.rb +8 -6
- data/lib/sidekiq-scheduler/version.rb +1 -1
- data/test/cli_test.rb +1 -13
- data/test/client_test.rb +1 -0
- metadata +11 -11
data/bin/sidekiq-scheduler
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
begin
|
4
|
-
require 'sidekiq-scheduler'
|
4
|
+
require 'sidekiq-scheduler/cli'
|
5
5
|
rescue LoadError
|
6
6
|
# Better way to do this in dev?
|
7
7
|
dir = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
@@ -10,7 +10,7 @@ rescue LoadError
|
|
10
10
|
end
|
11
11
|
|
12
12
|
begin
|
13
|
-
cli = Sidekiq::CLI.
|
13
|
+
cli = Sidekiq::CLI.instance
|
14
14
|
cli.parse
|
15
15
|
cli.run
|
16
16
|
rescue => e
|
data/lib/sidekiq-scheduler.rb
CHANGED
@@ -15,18 +15,18 @@ module SidekiqScheduler
|
|
15
15
|
item['class'] = item['class'].to_s if !item['class'].is_a?(String)
|
16
16
|
|
17
17
|
# Add item to the list for this timestamp
|
18
|
-
Sidekiq.redis.rpush("delayed:#{timestamp}", MultiJson.encode(item))
|
18
|
+
Sidekiq.redis { |r| r.rpush("delayed:#{timestamp}", MultiJson.encode(item)) }
|
19
19
|
|
20
20
|
# Add timestamp to zset. Score and value are based on the timestamp
|
21
21
|
# as querying will be based on that
|
22
|
-
Sidekiq.redis.zadd('delayed_queue_schedule', timestamp, timestamp)
|
22
|
+
Sidekiq.redis { |r| r.zadd('delayed_queue_schedule', timestamp, timestamp) }
|
23
23
|
end
|
24
24
|
|
25
25
|
def remove_scheduler_queue(timestamp)
|
26
26
|
key = "delayed:#{timestamp}"
|
27
|
-
if 0 == Sidekiq.redis.llen(key)
|
28
|
-
Sidekiq.redis.del(key)
|
29
|
-
Sidekiq.redis.zrem('delayed_queue_schedule', 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
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -53,8 +53,8 @@ module SidekiqScheduler
|
|
53
53
|
item = {'class' => klass.to_s, 'args' => args}
|
54
54
|
item['queue'] = queue.to_s if queue
|
55
55
|
search = MultiJson.encode(item)
|
56
|
-
Array(Sidekiq.redis.keys("delayed:*")).each do |key|
|
57
|
-
count += Sidekiq.redis.lrem(key, 0, search)
|
56
|
+
Array(Sidekiq.redis { |r| r.keys("delayed:*") }).each do |key|
|
57
|
+
count += Sidekiq.redis { |r| r.lrem(key, 0, search) }
|
58
58
|
end
|
59
59
|
count
|
60
60
|
end
|
@@ -77,7 +77,7 @@ module SidekiqScheduler
|
|
77
77
|
item = {'class' => klass.to_s, 'args' => args}
|
78
78
|
item['queue'] = queue.to_s if queue
|
79
79
|
search = MultiJson.encode(item)
|
80
|
-
count = Sidekiq.redis.lrem("delayed:#{timestamp}", 0, search)
|
80
|
+
count = Sidekiq.redis { |r| r.lrem("delayed:#{timestamp}", 0, search) }
|
81
81
|
remove_scheduler_queue(timestamp)
|
82
82
|
count
|
83
83
|
end
|
@@ -16,7 +16,7 @@ module SidekiqScheduler
|
|
16
16
|
include Celluloid
|
17
17
|
|
18
18
|
def initialize(options={})
|
19
|
-
logger.info "Booting sidekiq scheduler #{SidekiqScheduler::VERSION} with Redis at #{redis.client.location}"
|
19
|
+
logger.info "Booting sidekiq scheduler #{SidekiqScheduler::VERSION} with Redis at #{redis { |r| r.client.location} }"
|
20
20
|
logger.debug { options.inspect }
|
21
21
|
@enabled = options[:scheduler]
|
22
22
|
@resolution = options[:resolution] || 5
|
@@ -37,14 +37,16 @@ module SidekiqScheduler
|
|
37
37
|
private
|
38
38
|
|
39
39
|
def clear_scheduled_work
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
redis do |conn|
|
41
|
+
queues = conn.zrange('delayed_queue_schedule', 0, -1).to_a
|
42
|
+
conn.del(*queues.map { |t| "delayed:#{t}" }) unless queues.empty?
|
43
|
+
conn.del('delayed_queue_schedule')
|
44
|
+
end
|
43
45
|
end
|
44
46
|
|
45
47
|
def find_scheduled_work(timestamp)
|
46
48
|
loop do
|
47
|
-
break logger.debug("Finished processing queue for timestamp #{timestamp}") unless msg = redis.lpop("delayed:#{timestamp}")
|
49
|
+
break logger.debug("Finished processing queue for timestamp #{timestamp}") unless msg = redis { |r| r.lpop("delayed:#{timestamp}") }
|
48
50
|
item = MultiJson.decode(msg)
|
49
51
|
queue = item.delete('queue')
|
50
52
|
Sidekiq::Client.push(queue, item)
|
@@ -53,7 +55,7 @@ module SidekiqScheduler
|
|
53
55
|
end
|
54
56
|
|
55
57
|
def find_next_timestamp
|
56
|
-
timestamp = redis.zrangebyscore('delayed_queue_schedule', '-inf', Time.now.to_i, :limit => [0, 1])
|
58
|
+
timestamp = redis { |r| r.zrangebyscore('delayed_queue_schedule', '-inf', Time.now.to_i, :limit => [0, 1]) }
|
57
59
|
if timestamp.is_a?(Array)
|
58
60
|
timestamp = timestamp.first
|
59
61
|
end
|
data/test/cli_test.rb
CHANGED
@@ -5,7 +5,7 @@ require 'tempfile'
|
|
5
5
|
class CliTest < MiniTest::Unit::TestCase
|
6
6
|
describe 'with cli' do
|
7
7
|
before do
|
8
|
-
@cli =
|
8
|
+
@cli = Sidekiq::CLI.instance
|
9
9
|
end
|
10
10
|
|
11
11
|
describe 'with config file' do
|
@@ -17,17 +17,5 @@ class CliTest < MiniTest::Unit::TestCase
|
|
17
17
|
assert_equal 30, Sidekiq.options[:resolution]
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
21
|
-
def new_cli
|
22
|
-
cli = Sidekiq::CLI.new
|
23
|
-
def cli.die(code)
|
24
|
-
@code = code
|
25
|
-
end
|
26
|
-
|
27
|
-
def cli.valid?
|
28
|
-
!@code
|
29
|
-
end
|
30
|
-
cli
|
31
|
-
end
|
32
20
|
end
|
33
21
|
end
|
data/test/client_test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-scheduler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sidekiq
|
16
|
-
requirement: &
|
16
|
+
requirement: &70191338909220 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
21
|
+
version: 0.9.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70191338909220
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70191338907400 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70191338907400
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: timecop
|
38
|
-
requirement: &
|
38
|
+
requirement: &70191338906080 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70191338906080
|
47
47
|
description: Light weight job scheduling extension for Sidekiq that adds support for
|
48
48
|
queueing items in the future.
|
49
49
|
email:
|
@@ -88,7 +88,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
88
|
version: '0'
|
89
89
|
segments:
|
90
90
|
- 0
|
91
|
-
hash:
|
91
|
+
hash: -2828118743753619564
|
92
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
93
|
none: false
|
94
94
|
requirements:
|
@@ -97,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
97
|
version: '0'
|
98
98
|
segments:
|
99
99
|
- 0
|
100
|
-
hash:
|
100
|
+
hash: -2828118743753619564
|
101
101
|
requirements: []
|
102
102
|
rubyforge_project:
|
103
103
|
rubygems_version: 1.8.17
|