watership 0.0.1 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c575cdc499debb9ad8296a96c3ee511fdf23a6c
4
- data.tar.gz: 2453b523d5da8d128fcc633a80f6c676ad9b9630
3
+ metadata.gz: a8cd8b2ea2c5ed3da024e87f88da79df7c7fdddd
4
+ data.tar.gz: d23d7e5786d0fca043efaca34052ffb45abec9af
5
5
  SHA512:
6
- metadata.gz: 3d3e2a74ff9d30d48b6bd258d57a9eac5791e6262b9db943e7f9d2cc43d13cb91c27f5f731cf66ff4c6503005ec585f2c9dd2e8164580c5f6e473f3b3c5adcda
7
- data.tar.gz: d01b0387d2b83d53b3b4e3289e3b25db78e6760c9fe930e4be63dc9d2b083091c5de0142c04f6a3f619a28043597827738fb148799a31c114ca618ba277c0e34
6
+ metadata.gz: 36e76ad3e89aa8111d5f88db52eedaa6b5f967fa6ee4adf2b7ca84f6971943ce60076eb75d33b0a43e6a546542373b1c9a7a01e0d49143edcfb4ba4aa7930230
7
+ data.tar.gz: e2f2745ca837498e76089b085c101910b5c48e77e6dbca9e730ff51f854634c3745e53e7b5022246614ff663fbc9fa7d171bf1ebf7c1204e38f6be4da147199f
@@ -1,3 +1,3 @@
1
1
  module Watership
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/watership.rb CHANGED
@@ -1,5 +1,45 @@
1
- require "watership/version"
2
- require "watership/rarebit_queue"
3
- require "watership/rarebit_channel"
4
- require "watership/rarebit"
5
- require "watership/inle"
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.1
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-09 00:00:00.000000000 Z
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: ''
@@ -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
@@ -1,13 +0,0 @@
1
- module Watership
2
- class Rarebit
3
- def start; end
4
-
5
- def connected?
6
- false
7
- end
8
-
9
- def create_channel
10
- Watership::RarebitChannel.new
11
- end
12
- end
13
- end
@@ -1,7 +0,0 @@
1
- module Watership
2
- class RarebitChannel < Hash
3
- def queue(*args)
4
- self[args.first] = Watership::RarebitQueue.new
5
- end
6
- end
7
- end
@@ -1,12 +0,0 @@
1
- module Watership
2
- class RarebitQueue < Array
3
- def publish(payload)
4
- self << payload
5
- end
6
-
7
- def pop
8
- payload = super
9
- return nil, {}, payload
10
- end
11
- end
12
- end