bluth 0.6.1 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +26 -0
- data/Rakefile +3 -3
- data/VERSION.yml +1 -1
- data/bin/bluth +3 -3
- data/bluth.gemspec +6 -7
- data/lib/bluth.rb +22 -4
- data/lib/bluth/cli.rb +4 -2
- data/lib/bluth/worker.rb +17 -14
- data/try/16_worker_try.rb +1 -1
- data/try/19_bluth_try.rb +3 -3
- metadata +9 -10
- data/lib/bluth/gob.rb +0 -1
data/CHANGES.txt
CHANGED
@@ -1,5 +1,31 @@
|
|
1
1
|
BLUTH, CHANGES
|
2
2
|
|
3
|
+
#### 0.6.7 (2011-01-08) ###############################
|
4
|
+
|
5
|
+
* FIXED: -f option now works for stop-workers and stop-scheduler commands
|
6
|
+
* ADDED: Bluth.onconnect (resolves non-default redis connection issues)
|
7
|
+
|
8
|
+
|
9
|
+
#### 0.6.6 (2011-01-02) ###############################
|
10
|
+
|
11
|
+
CHANGE: Bluth::Worker.onstart
|
12
|
+
|
13
|
+
#### 0.6.5 (2011-01-02) ###############################
|
14
|
+
|
15
|
+
* FIXED: The previous change required a different approach for the scheduler.
|
16
|
+
|
17
|
+
#### 0.6.4 (2011-01-02) ###############################
|
18
|
+
|
19
|
+
* CHANGE: Don't save the worker until after onstart is called (b/c config info can be passed)
|
20
|
+
|
21
|
+
#### 0.6.3 (2011-01-02) ###############################
|
22
|
+
|
23
|
+
* CHANGE: Added :bluth prefix to Worker and Scheduler keys.
|
24
|
+
* CHANGE: Depends on Familia 0.6.5
|
25
|
+
* CHANGE: Option -r for bin/bluth is now -R
|
26
|
+
* CHANGE: Bluth.poptimeout -> Bluth.queuetimeout
|
27
|
+
|
28
|
+
|
3
29
|
#### 0.6.1 (2010-12-31) ###############################
|
4
30
|
|
5
31
|
* ADDED: Bluth.env
|
data/Rakefile
CHANGED
@@ -20,12 +20,12 @@ begin
|
|
20
20
|
gem.version = "#{config[:MAJOR]}.#{config[:MINOR]}.#{config[:PATCH]}"
|
21
21
|
gem.name = name
|
22
22
|
gem.rubyforge_project = gem.name
|
23
|
-
gem.summary = "A Redis queuing system built on top of Familia"
|
23
|
+
gem.summary = "A Redis queuing system built on top of Familia (w/ daemons!)"
|
24
24
|
gem.description = "A Redis queuing system built on top of Familia"
|
25
25
|
gem.email = "delano@solutious.com"
|
26
26
|
gem.homepage = "http://github.com/delano/bluth"
|
27
27
|
gem.authors = ["Delano Mandelbaum"]
|
28
|
-
gem.add_dependency("familia", "
|
28
|
+
gem.add_dependency("familia", ">= 0.6.5")
|
29
29
|
gem.add_dependency('sysinfo', '>= 0.7.3')
|
30
30
|
gem.add_dependency('annoy')
|
31
31
|
|
@@ -39,7 +39,7 @@ end
|
|
39
39
|
|
40
40
|
|
41
41
|
Rake::RDocTask.new do |rdoc|
|
42
|
-
version = "#{config[:MAJOR]}.#{config[:MINOR]}.#{config[:PATCH]}
|
42
|
+
version = "#{config[:MAJOR]}.#{config[:MINOR]}.#{config[:PATCH]}"
|
43
43
|
rdoc.rdoc_dir = "doc"
|
44
44
|
rdoc.title = "#{name} #{version}"
|
45
45
|
rdoc.rdoc_files.include("README*")
|
data/VERSION.yml
CHANGED
data/bin/bluth
CHANGED
@@ -42,10 +42,10 @@ class Bluth::CLI::Definition
|
|
42
42
|
@verbose ||= 0
|
43
43
|
@verbose += 1
|
44
44
|
end
|
45
|
-
global :I, String, "Add a load path" do |v|
|
45
|
+
global :I, :include, String, "Add a load path" do |v|
|
46
46
|
$LOAD_PATH << v
|
47
47
|
end
|
48
|
-
global :
|
48
|
+
global :R, :require, String, "Require a library" do |v|
|
49
49
|
$LOAD_PATH << 'lib' if File.exists? 'lib'
|
50
50
|
begin
|
51
51
|
require v
|
@@ -63,7 +63,7 @@ class Bluth::CLI::Definition
|
|
63
63
|
obj.global.environment ||= 'dev'
|
64
64
|
Bluth.env = obj.global.environment
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
#TODO: command :enqueue
|
68
68
|
|
69
69
|
command :start_worker => Bluth::CLI
|
data/bluth.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bluth}
|
8
|
-
s.version = "0.6.
|
8
|
+
s.version = "0.6.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Delano Mandelbaum"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-01-08}
|
13
13
|
s.default_executable = %q{bluth}
|
14
14
|
s.description = %q{A Redis queuing system built on top of Familia}
|
15
15
|
s.email = %q{delano@solutious.com}
|
@@ -28,7 +28,6 @@ Gem::Specification.new do |s|
|
|
28
28
|
"bluth.gemspec",
|
29
29
|
"lib/bluth.rb",
|
30
30
|
"lib/bluth/cli.rb",
|
31
|
-
"lib/bluth/gob.rb",
|
32
31
|
"lib/bluth/test_helpers.rb",
|
33
32
|
"lib/bluth/worker.rb",
|
34
33
|
"lib/daemonizing.rb",
|
@@ -43,23 +42,23 @@ Gem::Specification.new do |s|
|
|
43
42
|
s.require_paths = ["lib"]
|
44
43
|
s.rubyforge_project = %q{bluth}
|
45
44
|
s.rubygems_version = %q{1.3.7}
|
46
|
-
s.summary = %q{A Redis queuing system built on top of Familia}
|
45
|
+
s.summary = %q{A Redis queuing system built on top of Familia (w/ daemons!)}
|
47
46
|
|
48
47
|
if s.respond_to? :specification_version then
|
49
48
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
50
49
|
s.specification_version = 3
|
51
50
|
|
52
51
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
53
|
-
s.add_runtime_dependency(%q<familia>, ["
|
52
|
+
s.add_runtime_dependency(%q<familia>, [">= 0.6.5"])
|
54
53
|
s.add_runtime_dependency(%q<sysinfo>, [">= 0.7.3"])
|
55
54
|
s.add_runtime_dependency(%q<annoy>, [">= 0"])
|
56
55
|
else
|
57
|
-
s.add_dependency(%q<familia>, ["
|
56
|
+
s.add_dependency(%q<familia>, [">= 0.6.5"])
|
58
57
|
s.add_dependency(%q<sysinfo>, [">= 0.7.3"])
|
59
58
|
s.add_dependency(%q<annoy>, [">= 0"])
|
60
59
|
end
|
61
60
|
else
|
62
|
-
s.add_dependency(%q<familia>, ["
|
61
|
+
s.add_dependency(%q<familia>, [">= 0.6.5"])
|
63
62
|
s.add_dependency(%q<sysinfo>, [">= 0.7.3"])
|
64
63
|
s.add_dependency(%q<annoy>, [">= 0"])
|
65
64
|
end
|
data/lib/bluth.rb
CHANGED
@@ -35,7 +35,7 @@ module Bluth
|
|
35
35
|
class Shutdown < Familia::Problem; end
|
36
36
|
@db = 0
|
37
37
|
@env = :dev
|
38
|
-
@
|
38
|
+
@queuetimeout = 60 #.seconds
|
39
39
|
@handlers = []
|
40
40
|
@locks = []
|
41
41
|
@sysinfo = nil
|
@@ -43,11 +43,29 @@ module Bluth
|
|
43
43
|
@scheduler = nil
|
44
44
|
class << self
|
45
45
|
attr_reader :handlers, :db, :conf, :locks
|
46
|
-
attr_accessor :redis, :uri, :priority, :scheduler, :
|
46
|
+
attr_accessor :redis, :uri, :priority, :scheduler, :queuetimeout, :env
|
47
47
|
def sysinfo
|
48
48
|
@sysinfo ||= SysInfo.new.freeze
|
49
49
|
@sysinfo
|
50
50
|
end
|
51
|
+
# A block to be called before a worker starts.
|
52
|
+
#
|
53
|
+
# e.g.
|
54
|
+
# Bluth.onconnect do
|
55
|
+
# config = YourProject.load_config
|
56
|
+
# Familia.uri = config[:redis_uri]
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
# Note:
|
60
|
+
# this block can be called multiple times so do not
|
61
|
+
# put anything with side effects in here.
|
62
|
+
def onconnect &blk
|
63
|
+
@onconnect = blk unless blk.nil?
|
64
|
+
@onconnect
|
65
|
+
end
|
66
|
+
def connect
|
67
|
+
instance_eval &onconnect unless onconnect.nil?
|
68
|
+
end
|
51
69
|
end
|
52
70
|
|
53
71
|
def Bluth.clear_locks
|
@@ -98,7 +116,7 @@ module Bluth
|
|
98
116
|
end
|
99
117
|
|
100
118
|
# Workers use a blocking pop and will wait for up to
|
101
|
-
# Bluth.
|
119
|
+
# Bluth.queuetimeout (seconds) before returnning nil.
|
102
120
|
# Note that the queues are still processed in order.
|
103
121
|
# If all queues are empty, the first one to return a
|
104
122
|
# value is use. See:
|
@@ -119,7 +137,7 @@ module Bluth
|
|
119
137
|
gob = nil
|
120
138
|
begin
|
121
139
|
order = Bluth::Queue.entry_queues.collect(&:rediskey)
|
122
|
-
order << Bluth.
|
140
|
+
order << Bluth.queuetimeout # We do it this way to support Ruby 1.8
|
123
141
|
queue, gobid = *(Bluth::Queue.redis.send(meth, *order) || [])
|
124
142
|
unless queue.nil?
|
125
143
|
Familia.ld "FOUND #{gobid} id #{queue}"
|
data/lib/bluth/cli.rb
CHANGED
@@ -33,12 +33,13 @@ module Bluth
|
|
33
33
|
worker.daemonize
|
34
34
|
worker.run
|
35
35
|
else
|
36
|
-
Bluth.
|
36
|
+
Bluth.queuetimeout = 3.seconds
|
37
37
|
worker_class.run
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
def stop_workers worker_class=Bluth::Worker
|
42
|
+
Bluth.connect
|
42
43
|
worker_class.instances.each do |worker|
|
43
44
|
kill_worker worker, worker_class
|
44
45
|
end
|
@@ -46,6 +47,7 @@ module Bluth
|
|
46
47
|
|
47
48
|
def stop_worker wid=nil,worker_class=Bluth::Worker
|
48
49
|
wids = wid ? [wid] : @argv
|
50
|
+
Bluth.connect
|
49
51
|
wids.each do |wid|
|
50
52
|
worker = worker_class.from_redis wid
|
51
53
|
kill_worker worker, worker_class
|
@@ -64,7 +66,7 @@ module Bluth
|
|
64
66
|
exit 1
|
65
67
|
else
|
66
68
|
Familia.info "Killing #{worker.rediskey}"
|
67
|
-
worker.kill @
|
69
|
+
worker.kill @option.force
|
68
70
|
end
|
69
71
|
end
|
70
72
|
|
data/lib/bluth/worker.rb
CHANGED
@@ -27,8 +27,8 @@ module Bluth
|
|
27
27
|
|
28
28
|
def init(h=nil, u=nil, w=nil)
|
29
29
|
@host, @user, @wid, = h || Bluth.sysinfo.hostname, u || Bluth.sysinfo.user, w
|
30
|
-
@pid_file ||= "/tmp/#{
|
31
|
-
@log_file ||= "/tmp/#{
|
30
|
+
@pid_file ||= "/tmp/#{name}.pid"
|
31
|
+
@log_file ||= "/tmp/#{name}.log"
|
32
32
|
@success ||= 0
|
33
33
|
@failure ||= 0
|
34
34
|
@problem ||= 0
|
@@ -41,7 +41,7 @@ module Bluth
|
|
41
41
|
|
42
42
|
# Used by daemonize as the process name (linux only)
|
43
43
|
def name
|
44
|
-
|
44
|
+
[self.class.prefix, wid].flatten.join '-'
|
45
45
|
end
|
46
46
|
|
47
47
|
#def rediskey(suffix=nil)
|
@@ -121,7 +121,7 @@ module Bluth
|
|
121
121
|
include Familia
|
122
122
|
include Logging
|
123
123
|
include Daemonizable
|
124
|
-
prefix :worker
|
124
|
+
prefix [:bluth, :worker]
|
125
125
|
index [:host, :user, :wid]
|
126
126
|
field :host
|
127
127
|
field :user
|
@@ -145,6 +145,7 @@ module Bluth
|
|
145
145
|
|
146
146
|
def run!
|
147
147
|
begin
|
148
|
+
Bluth.connect
|
148
149
|
self.class.runblock :onstart
|
149
150
|
find_gob
|
150
151
|
rescue => ex
|
@@ -163,11 +164,12 @@ module Bluth
|
|
163
164
|
def run
|
164
165
|
begin
|
165
166
|
@process_id = $$
|
166
|
-
save
|
167
|
-
self.class.runblock :onstart
|
168
167
|
scheduler = Rufus::Scheduler.start_new
|
169
|
-
|
168
|
+
Bluth.connect
|
169
|
+
self.class.runblock :onstart
|
170
|
+
Familia.info "Setting interval: #{Worker.interval} sec (queuetimeout: #{Bluth.queuetimeout})"
|
170
171
|
Familia.reconnect_all! # Need to reconnect after daemonize
|
172
|
+
save
|
171
173
|
scheduler.every Worker.interval, :blocking => true do |task|
|
172
174
|
Familia.ld "#{$$} TICK @ #{Time.now.utc}"
|
173
175
|
sleep rand
|
@@ -184,7 +186,7 @@ module Bluth
|
|
184
186
|
rescue Interrupt => ex
|
185
187
|
puts <<-EOS.gsub(/(?:^|\n)\s*/, "\n")
|
186
188
|
Exiting...
|
187
|
-
(You may need to wait up to #{Bluth.
|
189
|
+
(You may need to wait up to #{Bluth.queuetimeout} seconds
|
188
190
|
for this worker to exit cleanly.)
|
189
191
|
EOS
|
190
192
|
# We reconnect to the queue in case we're currently
|
@@ -252,8 +254,6 @@ module Bluth
|
|
252
254
|
end
|
253
255
|
end
|
254
256
|
|
255
|
-
# TODO: Refactor somehow. When this is subclassed
|
256
|
-
# (eg BS::SchduleWorker) the self.object is not created.
|
257
257
|
class ScheduleWorker < Storable
|
258
258
|
include WorkerBase
|
259
259
|
include Familia
|
@@ -275,7 +275,7 @@ module Bluth
|
|
275
275
|
@every
|
276
276
|
end
|
277
277
|
end
|
278
|
-
prefix :scheduler
|
278
|
+
prefix [:bluth, :scheduler]
|
279
279
|
index [:host, :user, :wid]
|
280
280
|
field :host
|
281
281
|
field :user
|
@@ -291,13 +291,16 @@ module Bluth
|
|
291
291
|
|
292
292
|
def run
|
293
293
|
begin
|
294
|
-
raise Familia::Problem, "Only 1 scheduler at a time" if !ScheduleWorker.instances.empty?
|
295
294
|
EM.run {
|
296
295
|
@process_id = $$
|
297
296
|
srand(Bluth.salt.to_i(16) ** @process_id)
|
298
|
-
|
299
|
-
|
297
|
+
Bluth.connect
|
298
|
+
Familia.info "Setting interval: #{Worker.interval} sec (queuetimeout: #{Bluth.queuetimeout})"
|
299
|
+
Familia.reconnect_all! # Need to reconnect after daemonize
|
300
|
+
raise Familia::Problem, "Only 1 scheduler at a time" if !ScheduleWorker.instances.empty?
|
300
301
|
self.class.runblock :onstart
|
302
|
+
save # persist and make note the scheduler is running
|
303
|
+
ScheduleWorker.schedule = Rufus::Scheduler::EmScheduler.start_new
|
301
304
|
self.class.every.each do |args|
|
302
305
|
interval, opts, blk = *args
|
303
306
|
Familia.ld " scheduling every #{interval}: #{opts}"
|
data/try/16_worker_try.rb
CHANGED
data/try/19_bluth_try.rb
CHANGED
@@ -12,8 +12,8 @@ ExampleHandler.enqueue :item => :val3
|
|
12
12
|
Bluth::Queue.critical.size
|
13
13
|
#=> 3
|
14
14
|
|
15
|
-
## Can set
|
16
|
-
Bluth.
|
15
|
+
## Can set queuetimeout
|
16
|
+
Bluth.queuetimeout = 2
|
17
17
|
#=> 2
|
18
18
|
|
19
19
|
## Bluth.shift returns first value
|
@@ -31,7 +31,7 @@ Bluth.poptimeout = 2
|
|
31
31
|
@job3.data['item']
|
32
32
|
#=> 'val2'
|
33
33
|
|
34
|
-
## Bluth.pop returns nil after waiting for
|
34
|
+
## Bluth.pop returns nil after waiting for queuetimeout
|
35
35
|
Bluth.pop
|
36
36
|
#=> nil
|
37
37
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bluth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 7
|
10
|
+
version: 0.6.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Delano Mandelbaum
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-01-08 00:00:00 -05:00
|
19
19
|
default_executable: bluth
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -24,14 +24,14 @@ dependencies:
|
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- - "
|
27
|
+
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 13
|
30
30
|
segments:
|
31
31
|
- 0
|
32
32
|
- 6
|
33
|
-
-
|
34
|
-
version: 0.6.
|
33
|
+
- 5
|
34
|
+
version: 0.6.5
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
@@ -83,7 +83,6 @@ files:
|
|
83
83
|
- bluth.gemspec
|
84
84
|
- lib/bluth.rb
|
85
85
|
- lib/bluth/cli.rb
|
86
|
-
- lib/bluth/gob.rb
|
87
86
|
- lib/bluth/test_helpers.rb
|
88
87
|
- lib/bluth/worker.rb
|
89
88
|
- lib/daemonizing.rb
|
@@ -125,6 +124,6 @@ rubyforge_project: bluth
|
|
125
124
|
rubygems_version: 1.3.7
|
126
125
|
signing_key:
|
127
126
|
specification_version: 3
|
128
|
-
summary: A Redis queuing system built on top of Familia
|
127
|
+
summary: A Redis queuing system built on top of Familia (w/ daemons!)
|
129
128
|
test_files: []
|
130
129
|
|
data/lib/bluth/gob.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
|