watership 0.1.1 → 0.2.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: 102d250bba9e756c136c1aca5f39bdb47626f4b7
4
- data.tar.gz: 72a655309f210bf26e4e63825f8c8409a16b3c68
3
+ metadata.gz: 88ed411442bd7d22a020bf35b2977fa8045c28f0
4
+ data.tar.gz: a8b8d9ff4cca429b7349b9c49b5afff814f5dfc0
5
5
  SHA512:
6
- metadata.gz: e49f2338b90a7fca3685346b819a499ab5c761e4499569f3bc333a891bc21d0f5af0112ac2da1acee9ca28ad6e65e0438c655d0353b1978f809d8287928c380c
7
- data.tar.gz: 384e85f983fc9564c7659e10847b111ba61c8ca58d3ef8982c6dd42e16d949609a2fd7ffb19fd0fec2794f330b1f5f30d98f75dad7460d936b18383c82e22560
6
+ metadata.gz: c49ca8b9245b9a785cde330485f3a602586cc1d863d9f3f1e6f0ed4833eb0d6ed1b1f88670eff8e0c402f4dea6aaad63ceebdbad1e541d3150ac67887059804f
7
+ data.tar.gz: a7f0a9f4362792ea35b269cc445d0bcec29bf933639a676bd6895c1b46b24f81750d3fd82e8f512822868db82246e4edfb2d68d5abbf6443d7c7f456abf88550
@@ -1,3 +1,3 @@
1
1
  class Watership
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/watership.rb CHANGED
@@ -1,7 +1,6 @@
1
- require 'watership/version'
2
-
3
- require 'bunny'
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
- def self.config=(path)
15
- @config = IO.read(path).chomp
16
- end
13
+ class << self
14
+ def config=(path)
15
+ @config = IO.read(path).chomp
16
+ end
17
17
 
18
- def self.connect_to_rabbit
19
- $rabbit = Bunny.new(@config)
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
- $rabbit.start
22
- $channel = $rabbit.create_channel
23
- rescue *CONNECTION_EXCEPTIONS => e
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
- 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))
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
- Airbrake.notify(e) if defined?(Airbrake)
38
- logger.error e.class.name
39
- end
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
- def self.logger
42
- @logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
43
- end
49
+ def connection
50
+ Bunny.new(@config).tap { |bunny| bunny.start }
51
+ end
44
52
 
45
- end
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.1.1
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-22 00:00:00.000000000 Z
11
+ date: 2014-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler