urabbit 0.2.2 → 0.3.0

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: 1b3329408806f41ef02765e7c3e3f1f5e93ba02f
4
- data.tar.gz: 8c390e374d9c65aa13514be9be7d1d4190cc2aec
3
+ metadata.gz: d5a7ba1bc144820029a5de3c13bc0d162ac284e3
4
+ data.tar.gz: 7a8e01501892c9a51c9a2e806fc3206a6bc294e3
5
5
  SHA512:
6
- metadata.gz: fed11dbd4e61a2bad4c23ddcf16282484bdec771c857251d5011e751b732da6baac3c4b49538723eb789e863e16e09e6ac601df3c64ba2df3469dae8406ccb1c
7
- data.tar.gz: 5f7437305e2d1b43fc9d2c26b0092de4298f8f36b94564dc2a33d8d6e4e0be36a257cadbc17cf48617a92293715f6dacbc37f5d9bfbcdf32f05b28931f7dc38a
6
+ metadata.gz: 1f1c932ea346f3d413478a9758bd9a7b8e1a4228be989f4ff79763b15c00c05c087c6550e01dd01c87a4ed5928629c4575b3d31dac66ea55107b208ee66bbcf4
7
+ data.tar.gz: daa3dbf4de77cdf921ef189c4bc4f762f2d1832d833eedbbfc6bd806703cb241817e5366d5d26047f3aa8f0f86b4316702b003b211535a7d2434e58c5676666f
@@ -1,3 +1,3 @@
1
1
  module Urabbit
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/urabbit.rb CHANGED
@@ -5,6 +5,7 @@ require "securerandom"
5
5
 
6
6
  module Urabbit
7
7
  class Error < Exception; end
8
+ @mutex = Mutex.new
8
9
 
9
10
  def self.logger
10
11
  @logger ||= if defined?(Rails)
@@ -19,16 +20,24 @@ module Urabbit
19
20
  end
20
21
 
21
22
  # A single connection shared between threads.
22
- def self.connect(cloudamqp_url = ENV["CLOUDAMQP_URL"])
23
- @connection = Bunny.new(cloudamqp_url, logger: logger)
24
- @connection.start
25
- @connection
26
- rescue Bunny::Exception
27
- raise Error.new("Error connecting to RabbitMQ")
23
+ def self.connection(cloudamqp_url = ENV["CLOUDAMQP_URL"])
24
+ @mutex.synchronize do
25
+ @connection ||= begin
26
+ connection = Bunny.new(cloudamqp_url, logger: logger)
27
+ connection.start
28
+ connection
29
+ rescue Bunny::Exception
30
+ raise Error.new("Error connecting to RabbitMQ")
31
+ end
32
+ end
33
+ end
34
+
35
+ def self.disconnect
36
+ @connection = nil
28
37
  end
29
38
 
30
39
  def self.create_channel
31
- @connection.create_channel
40
+ connection.create_channel
32
41
  end
33
42
  end
34
43
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: urabbit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacek Becela
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-03 00:00:00.000000000 Z
11
+ date: 2016-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler