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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0705f27b3d44d5c4c7ecde03349eaa3748f56b7
4
- data.tar.gz: 6990d29b2d36f51d8075f6c68314429638f627c4
3
+ metadata.gz: 4d4160a86836f9eee120d3eeaebef6008cb06d83
4
+ data.tar.gz: d1cd55d8af1f209cf21490a4f587cd119d6548ad
5
5
  SHA512:
6
- metadata.gz: f95ffdb35728e7c4f4fa6ab2a8da8f167ea3d77bf551da75b98b80a4c120c9e52ad852209ffb6e918bd3fb48b7d1b2b14f4396d2b07cc42e332463bd418c6193
7
- data.tar.gz: 031f4a8efebfa49c4f5ce143ebd9fa7a8f01b749562121389279ffeb0b9ceab5f0dcf496021e82b9af262a93c84d795c946fca2a2701cdd71144eff3daaf110f
6
+ metadata.gz: 9471b130f5d5230b8346eab341ffb87f88167ba9d2b9475010e866cc0e5b172e228317f16f2ad593a3c8f7b11c5a794aec3390f8293707dad69714c84033b16e
7
+ data.tar.gz: 0adc7de6f975b6d7be3e863cf1acd84010fb3ac44329c03b65fa241ba74a01d29554f4e231f95724d46051e75c1f708c3b3493162fae658958d7e569ed1bd8b5
@@ -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
- ip_id = connection_sample
82
- connection = @connections[ip_id]
83
- begin
84
- job = connection.tubes[tube_name].reserve(timeout)
85
- return job
86
- rescue Beaneater::TimedOutError
87
- return nil
88
- rescue => ex
89
- notify(ex)
90
- notify("Exception IP: #{ip_id}")
91
- put_ip_in_timeout_and_reload(ip_id)
92
- return nil
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
- options = keystring_hash(options)
98
- pri = options["pri"] || 32000
99
- ttr = options["ttr"] || 60
100
- reset_use_tube = options['reset_use_tube']
101
- tube_name = options["tube_name"] || 'default'
102
- delay = (options["delay"]).to_i
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
- connection.tubes[tube_name].put(body, :pri => pri, :delay => delay, :ttr => ttr)
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)
@@ -1,3 +1,3 @@
1
1
  class Beanpool
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beanpool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason M.