pwwka 0.0.2 → 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 +4 -4
- data/Gemfile.lock +1 -7
- data/lib/pwwka.rb +0 -1
- data/lib/pwwka/transmitter.rb +35 -16
- data/lib/pwwka/version.rb +1 -1
- data/pwwka.gemspec +0 -1
- data/spec/spec_helper.rb +0 -3
- data/spec/transmitter_spec.rb +2 -7
- metadata +3 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cf3c8a949bbd8b4d824a31484de0349a16c79d9
|
4
|
+
data.tar.gz: 0f53407b75ed79d8cbd3d85cd5945e2a988edeba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 570f563f482b9992a0e9d55d8206ac74484d49ecfbc0d3b01d3819f5616f714b7e5f0203f21700a4b0011f6507daf06bc70dad7753a718430e51c99603f08b2d
|
7
|
+
data.tar.gz: 87786f3b94d21352bc2148708514eb8558d61edb3cfc80037a271ca8c69c50e9eb61fc5d22a3d2676615917469c5e1bacea5528243a2bd39315ea59317eaa2a1
|
data/Gemfile.lock
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pwwka (0.0
|
4
|
+
pwwka (0.1.0)
|
5
5
|
activemodel
|
6
6
|
activesupport
|
7
7
|
bunny
|
8
8
|
mono_logger
|
9
|
-
sucker_punch
|
10
9
|
|
11
10
|
GEM
|
12
11
|
remote: https://www.rubygems.org/
|
@@ -24,8 +23,6 @@ GEM
|
|
24
23
|
builder (3.2.2)
|
25
24
|
bunny (1.4.0)
|
26
25
|
amq-protocol (>= 1.9.2)
|
27
|
-
celluloid (0.15.2)
|
28
|
-
timers (~> 1.1.0)
|
29
26
|
diff-lcs (1.2.5)
|
30
27
|
i18n (0.6.11)
|
31
28
|
json (1.8.1)
|
@@ -44,10 +41,7 @@ GEM
|
|
44
41
|
rspec-mocks (3.0.4)
|
45
42
|
rspec-support (~> 3.0.0)
|
46
43
|
rspec-support (3.0.4)
|
47
|
-
sucker_punch (1.1)
|
48
|
-
celluloid (~> 0.15.2)
|
49
44
|
thread_safe (0.3.4)
|
50
|
-
timers (1.1.0)
|
51
45
|
tzinfo (1.2.2)
|
52
46
|
thread_safe (~> 0.1)
|
53
47
|
|
data/lib/pwwka.rb
CHANGED
data/lib/pwwka/transmitter.rb
CHANGED
@@ -1,27 +1,48 @@
|
|
1
1
|
module Pwwka
|
2
|
+
# Primary interface for sending messages.
|
3
|
+
#
|
4
|
+
# Example:
|
5
|
+
#
|
6
|
+
# # Send a message, blowing up if there's any problem
|
7
|
+
# Pwwka::Transmitter.send_message!({ user_id: @user.id }, "users.user.activated")
|
8
|
+
#
|
9
|
+
# # Send a message, logging if there's any problem
|
10
|
+
# Pwwka::Transmitter.send_message_safely({ user_id: @user.id }, "users.user.activated")
|
2
11
|
class Transmitter
|
3
12
|
|
4
13
|
extend Pwwka::Logging
|
5
|
-
include
|
14
|
+
include Pwwka::Logging
|
6
15
|
|
16
|
+
# Send an important message that must go through. This method allows any raised exception
|
17
|
+
# to pass through.
|
18
|
+
#
|
19
|
+
# payload:: Hash of what you'd like to include in your message
|
20
|
+
# routing_key:: String routing key for the message
|
21
|
+
#
|
22
|
+
# Returns true
|
23
|
+
#
|
24
|
+
# Raises any exception generated by the innerworkings of this library.
|
7
25
|
def self.send_message!(payload, routing_key)
|
8
|
-
new.
|
9
|
-
info "
|
26
|
+
new.send_message!(payload, routing_key)
|
27
|
+
info "AFTER Transmitting Message on #{routing_key} -> #{payload}"
|
10
28
|
end
|
11
29
|
|
30
|
+
# Send a less important message that doesn't have to go through. This eats
|
31
|
+
# any `StandardError` and logs it, returning false rather than blowing up.
|
32
|
+
#
|
33
|
+
# payload:: Hash of what you'd like to include in your message
|
34
|
+
# routing_key:: String routing key for the message
|
35
|
+
#
|
36
|
+
# Returns true if the message was sent, false otherwise
|
12
37
|
def self.send_message_safely(payload, routing_key)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
return false
|
18
|
-
end
|
38
|
+
send_message!(payload, routing_key)
|
39
|
+
rescue => e
|
40
|
+
error "ERROR Transmitting Message on #{routing_key} -> #{payload}: #{e}"
|
41
|
+
false
|
19
42
|
end
|
20
43
|
|
21
|
-
# send message asynchronously using sucker_punch
|
22
|
-
# call async.send_message!
|
23
44
|
def send_message!(payload, routing_key)
|
24
|
-
|
45
|
+
info "START Transmitting Message on #{routing_key} -> #{payload}"
|
25
46
|
channel_connector = ChannelConnector.new
|
26
47
|
channel_connector.topic_exchange.publish(
|
27
48
|
payload.to_json,
|
@@ -29,10 +50,8 @@ module Pwwka
|
|
29
50
|
persistent: true)
|
30
51
|
channel_connector.connection_close
|
31
52
|
# if it gets this far it has succeeded
|
32
|
-
|
33
|
-
|
53
|
+
info "END Transmitting Message on #{routing_key} -> #{payload}"
|
54
|
+
true
|
34
55
|
end
|
35
|
-
|
36
56
|
end
|
37
|
-
|
38
57
|
end
|
data/lib/pwwka/version.rb
CHANGED
data/pwwka.gemspec
CHANGED
@@ -21,7 +21,6 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.add_dependency("bunny")
|
22
22
|
s.add_dependency("activesupport")
|
23
23
|
s.add_dependency("activemodel")
|
24
|
-
s.add_dependency("sucker_punch")
|
25
24
|
s.add_dependency("mono_logger")
|
26
25
|
s.add_development_dependency("rake")
|
27
26
|
s.add_development_dependency("rspec")
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
GEM_ROOT = File.expand_path(File.join(File.dirname(__FILE__),'..'))
|
2
2
|
require 'pwwka'
|
3
3
|
require 'pwwka/test_handler'
|
4
|
-
require 'sucker_punch/testing/inline'
|
5
4
|
Dir["#{GEM_ROOT}/spec/support/**/*.rb"].sort.each {|f| require f}
|
6
5
|
|
7
6
|
RSpec.configure do |config|
|
8
7
|
|
9
|
-
SuckerPunch.logger = nil
|
10
|
-
|
11
8
|
config.expect_with :rspec do |c|
|
12
9
|
c.syntax = :expect
|
13
10
|
end
|
data/spec/transmitter_spec.rb
CHANGED
@@ -15,7 +15,7 @@ describe Pwwka::Transmitter do
|
|
15
15
|
describe "#send_message!" do
|
16
16
|
|
17
17
|
it "should send the correct payload" do
|
18
|
-
success = Pwwka::Transmitter.new.
|
18
|
+
success = Pwwka::Transmitter.new.send_message!(payload, routing_key)
|
19
19
|
expect(success).to be_truthy
|
20
20
|
received_payload = @test_handler.get_topic_message_payload_for_tests
|
21
21
|
expect(received_payload["this"]).to eq("that")
|
@@ -24,7 +24,7 @@ describe Pwwka::Transmitter do
|
|
24
24
|
it "should blow up if exception raised" do
|
25
25
|
expect(Pwwka::ChannelConnector).to receive(:new).and_raise("blow up")
|
26
26
|
expect {
|
27
|
-
Pwwka::Transmitter.new.
|
27
|
+
Pwwka::Transmitter.new.send_message!(payload, routing_key)
|
28
28
|
}.to raise_error
|
29
29
|
end
|
30
30
|
|
@@ -38,11 +38,6 @@ describe Pwwka::Transmitter do
|
|
38
38
|
expect(received_payload["this"]).to eq("that")
|
39
39
|
end
|
40
40
|
|
41
|
-
it "should use sucker_punch to send the message in the background" do
|
42
|
-
expect_any_instance_of(Pwwka::Transmitter).to receive(:send_message!).with(payload, routing_key).and_return(true)
|
43
|
-
Pwwka::Transmitter.send_message!(payload, routing_key)
|
44
|
-
end
|
45
|
-
|
46
41
|
it "should blow up if exception raised" do
|
47
42
|
expect(Pwwka::ChannelConnector).to receive(:new).and_raise("blow up")
|
48
43
|
expect{
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pwwka
|
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
|
- Stitch Fix Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: sucker_punch
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: mono_logger
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -163,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
149
|
version: '0'
|
164
150
|
requirements: []
|
165
151
|
rubyforge_project:
|
166
|
-
rubygems_version: 2.2.0
|
152
|
+
rubygems_version: 2.2.0.rc.1
|
167
153
|
signing_key:
|
168
154
|
specification_version: 4
|
169
155
|
summary: Send and receive messages via RabbitMQ
|