watership 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/watership/version.rb +1 -1
- data/lib/watership.rb +45 -5
- metadata +2 -6
- data/lib/watership/inle.rb +0 -44
- data/lib/watership/rarebit.rb +0 -13
- data/lib/watership/rarebit_channel.rb +0 -7
- data/lib/watership/rarebit_queue.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8cd8b2ea2c5ed3da024e87f88da79df7c7fdddd
|
4
|
+
data.tar.gz: d23d7e5786d0fca043efaca34052ffb45abec9af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36e76ad3e89aa8111d5f88db52eedaa6b5f967fa6ee4adf2b7ca84f6971943ce60076eb75d33b0a43e6a546542373b1c9a7a01e0d49143edcfb4ba4aa7930230
|
7
|
+
data.tar.gz: e2f2745ca837498e76089b085c101910b5c48e77e6dbca9e730ff51f854634c3745e53e7b5022246614ff663fbc9fa7d171bf1ebf7c1204e38f6be4da147199f
|
data/lib/watership/version.rb
CHANGED
data/lib/watership.rb
CHANGED
@@ -1,5 +1,45 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
|
1
|
+
require 'watership/version'
|
2
|
+
|
3
|
+
require 'bunny'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
class Watership
|
7
|
+
CONNECTION_EXCEPTIONS = [
|
8
|
+
Bunny::ClientTimeout,
|
9
|
+
Bunny::NetworkFailure,
|
10
|
+
Bunny::PossibleAuthenticationFailureError,
|
11
|
+
Bunny::TCPConnectionFailed
|
12
|
+
]
|
13
|
+
|
14
|
+
def self.config=(path)
|
15
|
+
@config = IO.read(path).chomp
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.connect_to_rabbit
|
19
|
+
$rabbit = Bunny.new(@config)
|
20
|
+
|
21
|
+
$rabbit.start
|
22
|
+
$channel = $rabbit.create_channel
|
23
|
+
rescue *CONNECTION_EXCEPTIONS => e
|
24
|
+
logger.warn(e.class.name)
|
25
|
+
$channel = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.enqueue(queue_name, data, options = {})
|
29
|
+
if $channel
|
30
|
+
queue = $channel.queue(queue_name, { durable: true }.merge(options))
|
31
|
+
queue.publish(JSON.generate(data))
|
32
|
+
end
|
33
|
+
rescue StandardError => e
|
34
|
+
# $channel.close
|
35
|
+
# $channel = nil # kill the channel so we stop trying to push to Rabbit
|
36
|
+
|
37
|
+
Airbrake.notify(e) if defined?(Airbrake)
|
38
|
+
logger.error e.class.name
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.logger
|
42
|
+
@logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: watership
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Scofield
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -65,10 +65,6 @@ files:
|
|
65
65
|
- README.md
|
66
66
|
- Rakefile
|
67
67
|
- lib/watership.rb
|
68
|
-
- lib/watership/inle.rb
|
69
|
-
- lib/watership/rarebit.rb
|
70
|
-
- lib/watership/rarebit_channel.rb
|
71
|
-
- lib/watership/rarebit_queue.rb
|
72
68
|
- lib/watership/version.rb
|
73
69
|
- watership.gemspec
|
74
70
|
homepage: ''
|
data/lib/watership/inle.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'logger'
|
2
|
-
require 'bunny'
|
3
|
-
|
4
|
-
module Watership
|
5
|
-
class Inle
|
6
|
-
@connection_options = {}
|
7
|
-
@connection = nil
|
8
|
-
@channel = nil
|
9
|
-
@last_connection_attempt = nil
|
10
|
-
@retry_timer = 10
|
11
|
-
|
12
|
-
def self.connect(options = {}, fake = false)
|
13
|
-
@connection_options.merge!(options)
|
14
|
-
@last_connection_attempt = Time.now
|
15
|
-
|
16
|
-
@connection = begin
|
17
|
-
Bunny.new @connection_options
|
18
|
-
rescue Bunny::TCPConnectionFailed, Bunny::NetworkFailure
|
19
|
-
fake = true
|
20
|
-
end unless fake
|
21
|
-
|
22
|
-
@connection = Watership::Rarebit.new if fake
|
23
|
-
|
24
|
-
@connection.start
|
25
|
-
@channel = @connection.create_channel
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.reconnect(fake = false)
|
29
|
-
connect({}, fake)
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.ensure_connection
|
33
|
-
if !(@connection && @connection.connected?) && time_to_try_again?
|
34
|
-
connect
|
35
|
-
end
|
36
|
-
|
37
|
-
@channel
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.time_to_try_again?
|
41
|
-
@last_connection_attempt.nil? || Time.now > @last_connection_attempt + @retry_timer
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
data/lib/watership/rarebit.rb
DELETED