honest_pubsub 0.2.2 → 0.2.4
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/LICENSE.txt +1 -1
- data/honest_pubsub.gemspec +2 -2
- data/lib/honest_pubsub/exceptions/payload_validation_error.rb +4 -0
- data/lib/honest_pubsub/server/client_queue_listener.rb +17 -15
- data/lib/honest_pubsub/server/client_worker.rb +26 -13
- data/lib/honest_pubsub/version.rb +1 -1
- data/lib/honest_pubsub.rb +1 -1
- metadata +8 -5
- data/lib/honest_pubsub/exceptions/payload_error.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7c53a089f1fad2b656c8134008f95ce5e4422e7
|
4
|
+
data.tar.gz: 32c4c3e5f5c90697fdc092d81d2f86e22c126ff1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4740278b6b995f74e69338bd600ef74e4803a67d1e5584179d73412ce894f889093079eabf594b91900cb0f34737eac393d0a43cef2c1664f0c15c179827220
|
7
|
+
data.tar.gz: e6f84c3ded8940652bdf7da0a21a9eb159dc633c75e9ae87da27d28cd74037ebb13ee53a5bffe6a84a9a15998af18e982042c151eb5ba1606df205dcde0b409a
|
data/LICENSE.txt
CHANGED
data/honest_pubsub.gemspec
CHANGED
@@ -8,8 +8,8 @@ require 'honest_pubsub/version'
|
|
8
8
|
Gem::Specification.new do |spec|
|
9
9
|
spec.name = "honest_pubsub"
|
10
10
|
spec.version = HonestPubsub::VERSION
|
11
|
-
spec.authors = ["Thanh Lim"]
|
12
|
-
spec.email = ["
|
11
|
+
spec.authors = ["tech@honest.com", "Thanh Lim", "tusharranka@gmail.com", "Joel Jackson"]
|
12
|
+
spec.email = ["webadmin@thehonestcompany.com"]
|
13
13
|
spec.description = "Pub sub gem for Honest Company"
|
14
14
|
spec.summary = "Pub sub gem for Honest Company"
|
15
15
|
spec.homepage = ""
|
@@ -11,12 +11,12 @@ module HonestPubsub
|
|
11
11
|
attr_reader :worker_class
|
12
12
|
|
13
13
|
def initialize(worker_class, request_key, queue, durable = true, topic = "honest")
|
14
|
-
@topic
|
15
|
-
@request_key
|
14
|
+
@topic = topic
|
15
|
+
@request_key = request_key
|
16
16
|
@worker_class = worker_class
|
17
|
-
@queue_name
|
18
|
-
@durable
|
19
|
-
@subscriber
|
17
|
+
@queue_name = queue
|
18
|
+
@durable = durable
|
19
|
+
@subscriber = ::HonestPubsub::Subscriber.new(@request_key, @durable, @topic)
|
20
20
|
end
|
21
21
|
|
22
22
|
def start
|
@@ -34,16 +34,18 @@ module HonestPubsub
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def message_received(delivery_info, properties, envelope)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
37
|
+
HonestPubsub.logger.debug("Message received by listener on #{worker_class.name} with payload: #{envelope[:payload]}")
|
38
|
+
worker = worker_class.new(delivery_info, properties)
|
39
|
+
worker.perform!(envelope[:context], envelope[:payload])
|
40
|
+
rescue => e
|
41
|
+
HonestPubsub.logger.error("Failed message for #{worker_class.name}")
|
42
|
+
Airbrake.notify("Failed perform for #{worker_class.name}",
|
43
|
+
params: {
|
44
|
+
info: delivery_info,
|
45
|
+
properties: properties,
|
46
|
+
context: envelope[:context],
|
47
|
+
payload: envelope[:payload] })
|
48
|
+
|
47
49
|
end
|
48
50
|
|
49
51
|
protected
|
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'active_support/core_ext'
|
3
3
|
|
4
|
+
# This class provders the worker for executing the subscriber. It receives a message from rabbitmq and
|
5
|
+
# creates an instance of the subscriber to execute with the message and context
|
6
|
+
|
4
7
|
module HonestPubsub
|
5
8
|
module Server
|
6
9
|
class ClientWorker
|
@@ -20,7 +23,7 @@ module HonestPubsub
|
|
20
23
|
unless validate_routing_key_name(routing_key_name)
|
21
24
|
raise ArgumentError.new("#{routing_key_name} is not supported. Only lower case characters separated by periods are allowed.")
|
22
25
|
end
|
23
|
-
self.subscribed_key
|
26
|
+
self.subscribed_key = routing_key_name
|
24
27
|
self.subscribed_queue = generated_queue_name(routing_key_name, options[:on])
|
25
28
|
end
|
26
29
|
|
@@ -32,13 +35,6 @@ module HonestPubsub
|
|
32
35
|
def self.validates_payload_with(*validators)
|
33
36
|
self.payload_validators ||= []
|
34
37
|
self.payload_validators += validators
|
35
|
-
#
|
36
|
-
# executable = if validator.class <= Proc then
|
37
|
-
# validator
|
38
|
-
# elsif validator.class == Symbol
|
39
|
-
# self.method(validator)
|
40
|
-
# end
|
41
|
-
# self.payload_validators.push executable
|
42
38
|
end
|
43
39
|
|
44
40
|
# Sets an error handler for the class
|
@@ -48,24 +44,41 @@ module HonestPubsub
|
|
48
44
|
|
49
45
|
def initialize(delivery_routing_data, delivery_properties)
|
50
46
|
@delivery_routing_data = delivery_routing_data
|
51
|
-
@delivery_properties
|
47
|
+
@delivery_properties = delivery_properties
|
48
|
+
end
|
49
|
+
|
50
|
+
# Performs validation if validates_payload_with is defined and then calls the perform method
|
51
|
+
# @param [Object] payload Payload of the message
|
52
|
+
# @param [Hash] context Context from invocation
|
53
|
+
def perform!(context, payload)
|
54
|
+
if !valid_payload?(payload)
|
55
|
+
HonestPubsub.logger.error("Payload validation failed for #{self.class.name}")
|
56
|
+
raise ::HonestPubsub::PayloadValidationError.new("Invalid Payload for #{self.class.name}")
|
57
|
+
end
|
58
|
+
|
59
|
+
perform(context, payload)
|
52
60
|
end
|
53
61
|
|
54
|
-
#
|
55
|
-
|
62
|
+
# Actual subscribers need to implement perform method. This is the method where the message is actually processed.
|
63
|
+
# @param [Object] payload Payload of the message
|
64
|
+
# @param [Hash] context Context from invocation
|
65
|
+
def perform(context, payload)
|
56
66
|
raise "Need implementation for your worker."
|
57
67
|
end
|
58
68
|
|
69
|
+
# @return [String] The original routing key with which the current message was published
|
59
70
|
def routing_key
|
60
71
|
delivery_routing_data[:routing_key]
|
61
72
|
end
|
62
73
|
|
63
74
|
# Iterates over all the payload validators and returns false if any of them are false
|
75
|
+
# @param [Object] payload The payload/arguments of the message
|
76
|
+
# @return [Boolen] Should return true or false value - If no validators are specified, then returns true
|
64
77
|
def valid_payload?(payload)
|
65
78
|
return true unless payload_validators.present?
|
66
79
|
|
67
80
|
payload_validators.inject(true) { |is_valid, validator|
|
68
|
-
is_valid && (validator.respond_to?(:call) ? validator.call(payload) : send(validator, payload)
|
81
|
+
is_valid && (validator.respond_to?(:call) ? validator.call(payload) : send(validator, payload))
|
69
82
|
}
|
70
83
|
end
|
71
84
|
|
@@ -78,7 +91,7 @@ module HonestPubsub
|
|
78
91
|
|
79
92
|
def self.generated_queue_name(routing_key, queue_name)
|
80
93
|
return queue_name if queue_name.present?
|
81
|
-
[
|
94
|
+
[HonestPubsub::Configuration.application_name.to_s.gsub(/[^\w\_]/, ''), routing_key.gsub(".", '_')].reject(&:blank?).join('_')
|
82
95
|
end
|
83
96
|
|
84
97
|
end
|
data/lib/honest_pubsub.rb
CHANGED
@@ -12,7 +12,7 @@ require "honest_pubsub/message"
|
|
12
12
|
require "honest_pubsub/publisher"
|
13
13
|
require "honest_pubsub/subscriber"
|
14
14
|
require "honest_pubsub/version"
|
15
|
-
require "honest_pubsub/exceptions/
|
15
|
+
require "honest_pubsub/exceptions/payload_validation_error"
|
16
16
|
require 'honest_pubsub/server'
|
17
17
|
|
18
18
|
if defined?(Rails::Railtie)
|
metadata
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: honest_pubsub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
+
- tech@honest.com
|
7
8
|
- Thanh Lim
|
9
|
+
- tusharranka@gmail.com
|
10
|
+
- Joel Jackson
|
8
11
|
autorequire:
|
9
12
|
bindir: bin
|
10
13
|
cert_chain: []
|
11
|
-
date: 2014-
|
14
|
+
date: 2014-07-01 00:00:00.000000000 Z
|
12
15
|
dependencies:
|
13
16
|
- !ruby/object:Gem::Dependency
|
14
17
|
name: bundler
|
@@ -180,7 +183,7 @@ dependencies:
|
|
180
183
|
version: '0.15'
|
181
184
|
description: Pub sub gem for Honest Company
|
182
185
|
email:
|
183
|
-
-
|
186
|
+
- webadmin@thehonestcompany.com
|
184
187
|
executables:
|
185
188
|
- start_subscribers
|
186
189
|
extensions: []
|
@@ -201,7 +204,7 @@ files:
|
|
201
204
|
- lib/honest_pubsub/configuration.rb
|
202
205
|
- lib/honest_pubsub/context.rb
|
203
206
|
- lib/honest_pubsub/db_logger.rb
|
204
|
-
- lib/honest_pubsub/exceptions/
|
207
|
+
- lib/honest_pubsub/exceptions/payload_validation_error.rb
|
205
208
|
- lib/honest_pubsub/logger.rb
|
206
209
|
- lib/honest_pubsub/logging.rb
|
207
210
|
- lib/honest_pubsub/message.rb
|
@@ -243,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
243
246
|
version: '0'
|
244
247
|
requirements: []
|
245
248
|
rubyforge_project:
|
246
|
-
rubygems_version: 2.
|
249
|
+
rubygems_version: 2.3.0
|
247
250
|
signing_key:
|
248
251
|
specification_version: 4
|
249
252
|
summary: Pub sub gem for Honest Company
|