watership 0.1.1 → 0.2.0
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.
- checksums.yaml +4 -4
- data/lib/watership/version.rb +1 -1
- data/lib/watership.rb +41 -29
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88ed411442bd7d22a020bf35b2977fa8045c28f0
|
4
|
+
data.tar.gz: a8b8d9ff4cca429b7349b9c49b5afff814f5dfc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c49ca8b9245b9a785cde330485f3a602586cc1d863d9f3f1e6f0ed4833eb0d6ed1b1f88670eff8e0c402f4dea6aaad63ceebdbad1e541d3150ac67887059804f
|
7
|
+
data.tar.gz: a7f0a9f4362792ea35b269cc445d0bcec29bf933639a676bd6895c1b46b24f81750d3fd82e8f512822868db82246e4edfb2d68d5abbf6443d7c7f456abf88550
|
data/lib/watership/version.rb
CHANGED
data/lib/watership.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require
|
4
|
-
require 'json'
|
1
|
+
require "bunny"
|
2
|
+
require "json"
|
3
|
+
require "watership/version"
|
5
4
|
|
6
5
|
class Watership
|
7
6
|
CONNECTION_EXCEPTIONS = [
|
@@ -11,35 +10,48 @@ class Watership
|
|
11
10
|
Bunny::TCPConnectionFailed
|
12
11
|
]
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
class << self
|
14
|
+
def config=(path)
|
15
|
+
@config = IO.read(path).chomp
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
def enqueue(options = {})
|
19
|
+
options = options.dup
|
20
|
+
message = options.delete(:message)
|
21
|
+
name = options.delete(:name)
|
22
|
+
fallback = options.delete(:fallback)
|
23
|
+
|
24
|
+
queue = connect_with_queue(name, options)
|
25
|
+
queue.publish(JSON.generate(message))
|
26
|
+
rescue StandardError => exception
|
27
|
+
fallback.call if fallback
|
28
|
+
Airbrake.notify(exception) if defined?(Airbrake)
|
29
|
+
logger.error(exception.class.name)
|
30
|
+
end
|
20
31
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
logger.warn(e.class.name)
|
25
|
-
$channel = nil
|
26
|
-
end
|
32
|
+
def connect_with_queue(name, options)
|
33
|
+
channel.queue(name, { durable: true }.merge(options))
|
34
|
+
end
|
27
35
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
36
|
+
def reconnect
|
37
|
+
$channel = nil
|
38
|
+
channel
|
39
|
+
true
|
32
40
|
end
|
33
|
-
rescue StandardError => e
|
34
|
-
# $channel.close
|
35
|
-
# $channel = nil # kill the channel so we stop trying to push to Rabbit
|
36
41
|
|
37
|
-
|
38
|
-
|
39
|
-
|
42
|
+
def channel
|
43
|
+
$channel ||= connection.create_channel
|
44
|
+
rescue *CONNECTION_EXCEPTIONS => exception
|
45
|
+
logger.warn(exception.class.name)
|
46
|
+
$channel = nil
|
47
|
+
end
|
40
48
|
|
41
|
-
|
42
|
-
|
43
|
-
|
49
|
+
def connection
|
50
|
+
Bunny.new(@config).tap { |bunny| bunny.start }
|
51
|
+
end
|
44
52
|
|
45
|
-
|
53
|
+
def logger
|
54
|
+
@logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
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.
|
4
|
+
version: 0.2.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-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|