action_pubsub 0.1.0 → 0.1.1
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/action_pubsub.gemspec +1 -0
- data/lib/action_pubsub/active_record/subscription.rb +23 -9
- data/lib/action_pubsub/config.rb +5 -0
- data/lib/action_pubsub/types.rb +19 -0
- data/lib/action_pubsub/version.rb +1 -1
- data/lib/action_pubsub.rb +6 -2
- metadata +17 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 84b10ab5fca7e4529071e72418eaf0848f2b76c5
|
|
4
|
+
data.tar.gz: 97a02cce5b9147716c7a80a497c2262227bc99c5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2098f79665ee6c3d0b067ab86a2f586613610a60c09e05b8b1b5c5dea6d289d16bbef56b2a1b887c1c408c0031a540fcc9b0e9c208106489776192827e130110
|
|
7
|
+
data.tar.gz: 17bd202a32d8393e5d62c34c5e5cf0a93b1760ddb0164721a1477edfb48ff35abb11e96e36c52dc789ffa7cc0e23a3066f88e5975ffff654395fd3f747e50f5d
|
data/action_pubsub.gemspec
CHANGED
|
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
|
|
|
25
25
|
spec.add_dependency "active_attr"
|
|
26
26
|
spec.add_dependency "activesupport"
|
|
27
27
|
spec.add_dependency "concurrent-ruby"
|
|
28
|
+
spec.add_dependency "trax_core"
|
|
28
29
|
spec.add_development_dependency "bundler", "~> 1.10"
|
|
29
30
|
spec.add_development_dependency 'guard', '~> 2'
|
|
30
31
|
spec.add_development_dependency 'guard-rspec', '~> 4'
|
|
@@ -7,18 +7,32 @@ module ActionPubsub
|
|
|
7
7
|
::ActionPubsub.exchange_registry[target_exchange][subscriber_key] << :subscribe
|
|
8
8
|
-> message {
|
|
9
9
|
::ActiveRecord::Base.connection_pool.with_connection do
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
begin
|
|
11
|
+
message = ::ActionPubsub.deserialize_event(message)
|
|
12
|
+
reaction = self.class.subscriber.reactions[message["action"]]
|
|
13
|
+
record = message["record"]
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
if self.class.subscriber.react?(message["action"], reaction, record)
|
|
16
|
+
self.class.subscriber.increment_event_triggered_count!
|
|
17
|
+
subscriber_instance = self.class.subscriber.new(record)
|
|
18
|
+
subscriber_instance.instance_exec(record, &reaction[:block])
|
|
19
|
+
end
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
self.class.bind_subscription(target_exchange, subscriber_key)
|
|
22
|
+
rescue => e
|
|
23
|
+
#ensure we rebind subscription regardless
|
|
24
|
+
self.class.bind_subscription(target_exchange, subscriber_key)
|
|
25
|
+
message = ::ActionPubsub.deserialize_event(message)
|
|
26
|
+
|
|
27
|
+
failure_message = ::ActionPubsub::Types::SubscriptionReactionError.new(
|
|
28
|
+
:target_exchange => target_exchange,
|
|
29
|
+
:subscriber_key => subscriber_key,
|
|
30
|
+
:error => e,
|
|
31
|
+
:message => message
|
|
32
|
+
)
|
|
20
33
|
|
|
21
|
-
|
|
34
|
+
::ActionPubsub.config._on_error_block.call(failure_message) if ::ActionPubsub.config._on_error_block
|
|
35
|
+
end
|
|
22
36
|
end
|
|
23
37
|
}
|
|
24
38
|
end
|
data/lib/action_pubsub/config.rb
CHANGED
|
@@ -7,6 +7,7 @@ module ActionPubsub
|
|
|
7
7
|
|
|
8
8
|
self[:debug] = false
|
|
9
9
|
self[:serializer] = nil
|
|
10
|
+
self[:_on_error_block] = nil
|
|
10
11
|
end
|
|
11
12
|
|
|
12
13
|
def debug=(val)
|
|
@@ -18,5 +19,9 @@ module ActionPubsub
|
|
|
18
19
|
::ActionPubsub.include(val)
|
|
19
20
|
end
|
|
20
21
|
end
|
|
22
|
+
|
|
23
|
+
def on_error(&block)
|
|
24
|
+
self[:_on_error_block] = block
|
|
25
|
+
end
|
|
21
26
|
end
|
|
22
27
|
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'trax_core'
|
|
2
|
+
|
|
3
|
+
module ActionPubsub
|
|
4
|
+
class Types < ::Trax::Core::Blueprint
|
|
5
|
+
class SubscriptionReactionError < ::Trax::Core::Types::Struct
|
|
6
|
+
string :target_exchange
|
|
7
|
+
string :subscriber_key
|
|
8
|
+
|
|
9
|
+
attr_accessor :message, :error
|
|
10
|
+
|
|
11
|
+
def initialize(*args, message:, error:, **options)
|
|
12
|
+
super(*args, **options)
|
|
13
|
+
|
|
14
|
+
@message = message
|
|
15
|
+
@error = error
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
data/lib/action_pubsub.rb
CHANGED
|
@@ -5,6 +5,7 @@ require "active_attr"
|
|
|
5
5
|
require "concurrent/lazy_register"
|
|
6
6
|
require "concurrent/actor"
|
|
7
7
|
require "concurrent/agent"
|
|
8
|
+
require "trax_core"
|
|
8
9
|
|
|
9
10
|
module ActionPubsub
|
|
10
11
|
extend ::ActiveSupport::Autoload
|
|
@@ -19,9 +20,14 @@ module ActionPubsub
|
|
|
19
20
|
autoload :Logging
|
|
20
21
|
autoload :Subscriber
|
|
21
22
|
autoload :Queue
|
|
23
|
+
autoload :Types
|
|
22
24
|
|
|
23
25
|
@configuration ||= ::ActionPubsub::Config.new
|
|
24
26
|
|
|
27
|
+
def self.configure(&block)
|
|
28
|
+
block.call(config)
|
|
29
|
+
end
|
|
30
|
+
|
|
25
31
|
def self.event_count
|
|
26
32
|
@event_count ||= ::Concurrent::Agent.new(0)
|
|
27
33
|
end
|
|
@@ -30,8 +36,6 @@ module ActionPubsub
|
|
|
30
36
|
@exchange_registry ||= ::ActionPubsub::ExchangeRegistry.new
|
|
31
37
|
end
|
|
32
38
|
|
|
33
|
-
@some_registry = ::Concurrent::LazyRegister.new
|
|
34
|
-
|
|
35
39
|
def self.destination_tuple_from_path(path_string)
|
|
36
40
|
segs = path_string.split("/")
|
|
37
41
|
worker_index = segs.pop
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: action_pubsub
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jason Ayre
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-
|
|
11
|
+
date: 2015-11-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: active_attr
|
|
@@ -52,6 +52,20 @@ dependencies:
|
|
|
52
52
|
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: trax_core
|
|
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'
|
|
55
69
|
- !ruby/object:Gem::Dependency
|
|
56
70
|
name: bundler
|
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -283,6 +297,7 @@ files:
|
|
|
283
297
|
- lib/action_pubsub/serialization.rb
|
|
284
298
|
- lib/action_pubsub/serialization/marshal.rb
|
|
285
299
|
- lib/action_pubsub/subscriber.rb
|
|
300
|
+
- lib/action_pubsub/types.rb
|
|
286
301
|
- lib/action_pubsub/version.rb
|
|
287
302
|
homepage: http://github.com/jasonayre/action_pubsub
|
|
288
303
|
licenses:
|