beanstalker 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/init.rb +1 -1
- data/lib/async_observer/daemonizer_handler.rb +2 -2
- data/lib/async_observer/extend.rb +4 -4
- data/lib/async_observer/queue.rb +9 -9
- data/lib/async_observer/worker.rb +9 -9
- metadata +3 -4
- data/glebpom-async_observer.gemspec +0 -56
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/init.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require '
|
1
|
+
require 'beanstalker/extend'
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module
|
1
|
+
module Beanstalker
|
2
2
|
class DaemonizerHandler < Daemonizer::Handler
|
3
3
|
def prepare(block)
|
4
4
|
logger.info "Loading Rails"
|
5
5
|
require File.join(Daemonizer.root, '/config/environment')
|
6
|
-
require '
|
6
|
+
require 'beanstalker/worker'
|
7
7
|
logger.info "Rails loaded"
|
8
8
|
super
|
9
9
|
end
|
@@ -15,7 +15,7 @@
|
|
15
15
|
# You should have received a copy of the GNU General Public License
|
16
16
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
17
|
|
18
|
-
require '
|
18
|
+
require 'beanstalker/queue'
|
19
19
|
|
20
20
|
CLASSES_TO_EXTEND = [
|
21
21
|
ActiveRecord::Base,
|
@@ -28,7 +28,7 @@ CLASSES_TO_EXTEND = [
|
|
28
28
|
Symbol,
|
29
29
|
]
|
30
30
|
|
31
|
-
module
|
31
|
+
module Beanstalker::Extensions
|
32
32
|
def self.included(receiver)
|
33
33
|
@@methods_async_options = {}
|
34
34
|
receiver.extend(ClassMethods)
|
@@ -61,12 +61,12 @@ module AsyncObserver::Extensions
|
|
61
61
|
|
62
62
|
def async_send_opts(selector, opts, *args)
|
63
63
|
interpolated_options = interpolate_async_options(opts, self)
|
64
|
-
|
64
|
+
Beanstalker::Queue.put_call!(self, selector, interpolated_options, args)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
CLASSES_TO_EXTEND.each do |c|
|
69
|
-
c.send :include,
|
69
|
+
c.send :include, Beanstalker::Extensions
|
70
70
|
end
|
71
71
|
|
72
72
|
class Range
|
data/lib/async_observer/queue.rb
CHANGED
@@ -18,11 +18,11 @@
|
|
18
18
|
|
19
19
|
require 'beanstalk-client'
|
20
20
|
|
21
|
-
module
|
21
|
+
module Beanstalker; end
|
22
22
|
|
23
|
-
class
|
23
|
+
class Beanstalker::Queue; end
|
24
24
|
|
25
|
-
class <<
|
25
|
+
class << Beanstalker::Queue
|
26
26
|
DEFAULT_PRI = 512
|
27
27
|
DEFAULT_FUZZ = 0
|
28
28
|
DEFAULT_DELAY = 0
|
@@ -33,14 +33,14 @@ class << AsyncObserver::Queue
|
|
33
33
|
|
34
34
|
# This is a fake worker instance for running jobs synchronously.
|
35
35
|
def sync_worker()
|
36
|
-
require '
|
37
|
-
@sync_worker ||=
|
36
|
+
require 'beanstalker/worker'
|
37
|
+
@sync_worker ||= Beanstalker::Worker.new(binding)
|
38
38
|
end
|
39
39
|
|
40
40
|
# This runs jobs synchronously; it's used when no queue is configured.
|
41
41
|
def sync_run(obj)
|
42
42
|
body = YAML.dump(obj)
|
43
|
-
job = Beanstalk::Job.new(
|
43
|
+
job = Beanstalk::Job.new(Beanstalker::FakeConn.new(), 0, body)
|
44
44
|
sync_worker.dispatch(job)
|
45
45
|
sync_worker.do_all_work()
|
46
46
|
return 0, '0.0.0.0'
|
@@ -52,7 +52,7 @@ class << AsyncObserver::Queue
|
|
52
52
|
queue.connect()
|
53
53
|
queue.use(tube)
|
54
54
|
info = [queue.yput(obj, pri, delay, ttr), queue.last_server]
|
55
|
-
f =
|
55
|
+
f = Beanstalker::Queue.after_put
|
56
56
|
f.call(*info) if f
|
57
57
|
return info
|
58
58
|
end
|
@@ -95,7 +95,7 @@ class << AsyncObserver::Queue
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
-
class
|
98
|
+
class Beanstalker::FakeConn
|
99
99
|
def delete(x)
|
100
100
|
end
|
101
101
|
|
@@ -181,7 +181,7 @@ class Date
|
|
181
181
|
def rrepr() "Date.parse('#{self.inspect}')" end
|
182
182
|
end
|
183
183
|
|
184
|
-
module
|
184
|
+
module Beanstalker::Extensions
|
185
185
|
def rrepr()
|
186
186
|
method = (respond_to? :get_cache) ? 'get_cache' : 'find'
|
187
187
|
"#{self.class.rrepr}.#{method}(#{id.rrepr})"
|
@@ -15,11 +15,11 @@
|
|
15
15
|
# You should have received a copy of the GNU General Public License
|
16
16
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
17
|
|
18
|
-
require '
|
18
|
+
require 'beanstalker/queue'
|
19
19
|
|
20
|
-
module
|
20
|
+
module Beanstalker; end
|
21
21
|
|
22
|
-
class
|
22
|
+
class Beanstalker::Worker
|
23
23
|
|
24
24
|
SLEEP_TIME = 60 if !defined?(SLEEP_TIME) # rails loads this file twice
|
25
25
|
|
@@ -59,7 +59,7 @@ class AsyncObserver::Worker
|
|
59
59
|
@stop = false
|
60
60
|
@options = options
|
61
61
|
if @options && @options[:servers]
|
62
|
-
|
62
|
+
Beanstalker::Queue.queue = Beanstalk::Pool.new(@options[:servers])
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -74,7 +74,7 @@ class AsyncObserver::Worker
|
|
74
74
|
def startup
|
75
75
|
tube = @options[:tube] || "default"
|
76
76
|
logger.info "Using tube #{tube}"
|
77
|
-
|
77
|
+
Beanstalker::Queue.queue.watch(tube)
|
78
78
|
flush_logger
|
79
79
|
end
|
80
80
|
|
@@ -90,7 +90,7 @@ class AsyncObserver::Worker
|
|
90
90
|
end
|
91
91
|
|
92
92
|
def q_hint
|
93
|
-
@q_hint ||
|
93
|
+
@q_hint || Beanstalker::Queue.queue
|
94
94
|
end
|
95
95
|
|
96
96
|
# This heuristic is to help prevent one queue from starving. The idea is that
|
@@ -112,7 +112,7 @@ class AsyncObserver::Worker
|
|
112
112
|
def get_job
|
113
113
|
loop do
|
114
114
|
begin
|
115
|
-
|
115
|
+
Beanstalker::Queue.queue.connect
|
116
116
|
self.class.run_before_reserve
|
117
117
|
return reserve_and_set_hint
|
118
118
|
rescue Interrupt => ex
|
@@ -136,7 +136,7 @@ class AsyncObserver::Worker
|
|
136
136
|
|
137
137
|
def dispatch(job)
|
138
138
|
ActiveRecord::Base.verify_active_connections!
|
139
|
-
return run_ao_job(job) if
|
139
|
+
return run_ao_job(job) if beanstalker_job?(job)
|
140
140
|
return run_other(job)
|
141
141
|
end
|
142
142
|
|
@@ -205,7 +205,7 @@ class AsyncObserver::Worker
|
|
205
205
|
eval(job.ybody[:code], @top_binding, "(beanstalk job #{job.id})", 1)
|
206
206
|
end
|
207
207
|
|
208
|
-
def
|
208
|
+
def beanstalker_job?(job)
|
209
209
|
begin job.ybody[:type] == :rails rescue false end
|
210
210
|
end
|
211
211
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beanstalker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gleb Pomykalov
|
@@ -78,7 +78,6 @@ files:
|
|
78
78
|
- README
|
79
79
|
- Rakefile
|
80
80
|
- VERSION
|
81
|
-
- glebpom-async_observer.gemspec
|
82
81
|
- init.rb
|
83
82
|
- lib/async_observer/daemonizer_handler.rb
|
84
83
|
- lib/async_observer/extend.rb
|
@@ -1,56 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{glebpom-async_observer}
|
8
|
-
s.version = "0.1.0"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Gleb Pomykalov"]
|
12
|
-
s.date = %q{2010-07-14}
|
13
|
-
s.description = %q{async_observer provides deep integration with Beanstalk. Fork from http://github.com/kristjan/async_observer}
|
14
|
-
s.email = %q{glebpom@gmail.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"README"
|
17
|
-
]
|
18
|
-
s.files = [
|
19
|
-
".gitignore",
|
20
|
-
"COPYING",
|
21
|
-
"README",
|
22
|
-
"Rakefile",
|
23
|
-
"VERSION",
|
24
|
-
"glebpom-async_observer.gemspec",
|
25
|
-
"init.rb",
|
26
|
-
"lib/async_observer/daemonizer_handler.rb",
|
27
|
-
"lib/async_observer/extend.rb",
|
28
|
-
"lib/async_observer/queue.rb",
|
29
|
-
"lib/async_observer/worker.rb"
|
30
|
-
]
|
31
|
-
s.homepage = %q{http://github.com/glebpom/async_observer}
|
32
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
33
|
-
s.require_paths = ["lib"]
|
34
|
-
s.rubygems_version = %q{1.3.7}
|
35
|
-
s.summary = %q{async_observer provides deep integration with Beanstalk. Fork from http://github.com/kristjan/async_observer}
|
36
|
-
|
37
|
-
if s.respond_to? :specification_version then
|
38
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
39
|
-
s.specification_version = 3
|
40
|
-
|
41
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
42
|
-
s.add_runtime_dependency(%q<daemonizer>, ["~> 0.2.0"])
|
43
|
-
s.add_runtime_dependency(%q<beanstalk-client>, [">= 0"])
|
44
|
-
s.add_runtime_dependency(%q<rails>, [">= 2.2.0"])
|
45
|
-
else
|
46
|
-
s.add_dependency(%q<daemonizer>, ["~> 0.2.0"])
|
47
|
-
s.add_dependency(%q<beanstalk-client>, [">= 0"])
|
48
|
-
s.add_dependency(%q<rails>, [">= 2.2.0"])
|
49
|
-
end
|
50
|
-
else
|
51
|
-
s.add_dependency(%q<daemonizer>, ["~> 0.2.0"])
|
52
|
-
s.add_dependency(%q<beanstalk-client>, [">= 0"])
|
53
|
-
s.add_dependency(%q<rails>, [">= 2.2.0"])
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|