beanpool 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/beanpool/connections.rb +35 -29
- data/lib/beanpool/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d4160a86836f9eee120d3eeaebef6008cb06d83
|
4
|
+
data.tar.gz: d1cd55d8af1f209cf21490a4f587cd119d6548ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9471b130f5d5230b8346eab341ffb87f88167ba9d2b9475010e866cc0e5b172e228317f16f2ad593a3c8f7b11c5a794aec3390f8293707dad69714c84033b16e
|
7
|
+
data.tar.gz: 0adc7de6f975b6d7be3e863cf1acd84010fb3ac44329c03b65fa241ba74a01d29554f4e231f95724d46051e75c1f708c3b3493162fae658958d7e569ed1bd8b5
|
data/lib/beanpool/connections.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'beaneater'
|
2
|
+
require 'thread'
|
2
3
|
|
3
4
|
class Beanpool
|
4
5
|
class Connections
|
@@ -10,6 +11,7 @@ class Beanpool
|
|
10
11
|
@connections = {}
|
11
12
|
@debug = debug
|
12
13
|
build_connections
|
14
|
+
@mutex = Mutex.new
|
13
15
|
end
|
14
16
|
|
15
17
|
def notify(object)
|
@@ -78,43 +80,47 @@ class Beanpool
|
|
78
80
|
end
|
79
81
|
|
80
82
|
def get_job_from_tube(timeout = nil, tube_name = 'default')
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
83
|
+
@mutex.synchronize do
|
84
|
+
ip_id = connection_sample
|
85
|
+
connection = @connections[ip_id]
|
86
|
+
begin
|
87
|
+
job = connection.tubes[tube_name].reserve(timeout)
|
88
|
+
return job
|
89
|
+
rescue Beaneater::TimedOutError
|
90
|
+
return nil
|
91
|
+
rescue => ex
|
92
|
+
notify(ex)
|
93
|
+
notify("Exception IP: #{ip_id}")
|
94
|
+
put_ip_in_timeout_and_reload(ip_id)
|
95
|
+
return nil
|
96
|
+
end
|
93
97
|
end
|
94
98
|
end
|
95
99
|
|
96
100
|
def put_job_to_tube(body, options)
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
101
|
+
@mutex.synchronize do
|
102
|
+
options = keystring_hash(options)
|
103
|
+
pri = options["pri"] || 32000
|
104
|
+
ttr = options["ttr"] || 60
|
105
|
+
reset_use_tube = options['reset_use_tube']
|
106
|
+
tube_name = options["tube_name"] || 'default'
|
107
|
+
delay = (options["delay"]).to_i
|
103
108
|
|
104
|
-
ip_id = connection_sample
|
105
|
-
connection = @connections[ip_id]
|
106
|
-
begin
|
107
|
-
notify("BEANPOOL: Putting to #{tube_name}")
|
108
|
-
connection.tubes[tube_name].put(body, :pri => pri, :delay => delay, :ttr => ttr)
|
109
|
-
rescue => ex
|
110
|
-
notify(ex)
|
111
|
-
put_ip_in_timeout_and_reload(ip_id)
|
112
109
|
ip_id = connection_sample
|
113
110
|
connection = @connections[ip_id]
|
114
|
-
|
111
|
+
begin
|
112
|
+
notify("BEANPOOL: Putting to #{tube_name}")
|
113
|
+
connection.tubes[tube_name].put(body, :pri => pri, :delay => delay, :ttr => ttr)
|
114
|
+
rescue => ex
|
115
|
+
notify(ex)
|
116
|
+
put_ip_in_timeout_and_reload(ip_id)
|
117
|
+
ip_id = connection_sample
|
118
|
+
connection = @connections[ip_id]
|
119
|
+
connection.tubes[tube_name].put(body, :pri => pri, :delay => delay, :ttr => ttr)
|
120
|
+
end
|
121
|
+
# Force default tube reset if requested.
|
122
|
+
connection.tubes.use(reset_use_tube) if connection && reset_use_tube
|
115
123
|
end
|
116
|
-
# Force default tube reset if requested.
|
117
|
-
connection.tubes.use(reset_use_tube) if connection && reset_use_tube
|
118
124
|
end
|
119
125
|
|
120
126
|
def keystring_hash(hash)
|
data/lib/beanpool/version.rb
CHANGED