icalia-sdk-event-notification 0.1.10 → 0.1.13
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 109e08255174b6123e57a7e78f1ef0070a6b1df9a08625aa264d0da59bc7e6b1
|
4
|
+
data.tar.gz: 8d1df1d8b155db6cdcb7add13e17fb4f6bf16fc972b5eb5e0175a62d014339bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1393bedd16f478a3d658e20770ca9b65d70d40fff1390580b2d491f7d4a07752da2f01599b33c6a76e1d891b078afb7a2393c32a9431273de4ccafc8b6869d42
|
7
|
+
data.tar.gz: 22796d27e9f973008c558c24f823dcd0ccd7db9576ab7dba0c461bdac19a063ead7b2ced47a3d0e403419aff16aa89ddc33d6aae62bdb39758f22cb1de47cecb
|
@@ -13,9 +13,6 @@ module Icalia
|
|
13
13
|
|
14
14
|
autoload :Shoryuken, 'icalia-sdk-event-notification/shoryuken'
|
15
15
|
|
16
|
-
autoload :EventTriggeringRecord,
|
17
|
-
'icalia-sdk-event-notification/event_triggering_record'
|
18
|
-
|
19
16
|
autoload :TopicMessageProcessing,
|
20
17
|
'icalia-sdk-event-notification/topic_message_processing'
|
21
18
|
|
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'aws-sdk-sns'
|
4
4
|
|
5
|
+
require 'active_support'
|
6
|
+
require 'active_support/logger'
|
7
|
+
|
5
8
|
module Icalia::Event
|
6
9
|
class Publisher
|
7
10
|
|
@@ -16,10 +19,11 @@ module Icalia::Event
|
|
16
19
|
delegate :publish, to: :instance
|
17
20
|
end
|
18
21
|
|
19
|
-
attr_reader :sns_client
|
22
|
+
attr_reader :sns_client, :logger
|
20
23
|
|
21
24
|
def initialize
|
22
|
-
|
25
|
+
set_sns_client
|
26
|
+
set_logger
|
23
27
|
end
|
24
28
|
|
25
29
|
def publish(topic_name, data, json_data: true)
|
@@ -27,6 +31,7 @@ module Icalia::Event
|
|
27
31
|
unless topic_exists?(topic_name)
|
28
32
|
|
29
33
|
topic = get_topic topic_name
|
34
|
+
logger.debug "Publishing to '#{topic_name}': #{data.inspect}"
|
30
35
|
topic.publish message: (json_data ? json_encode(data) : data)
|
31
36
|
end
|
32
37
|
|
@@ -43,5 +48,26 @@ module Icalia::Event
|
|
43
48
|
def topic_exists?(topic_name)
|
44
49
|
get_topic(topic_name).present?
|
45
50
|
end
|
51
|
+
|
52
|
+
def set_sns_client
|
53
|
+
@sns_client = Aws::SNS::Resource.new Icalia::Event.sns_client_options
|
54
|
+
end
|
55
|
+
|
56
|
+
def set_logger
|
57
|
+
return use_rails_logger if rails_logger_exist?
|
58
|
+
use_default_logger
|
59
|
+
end
|
60
|
+
|
61
|
+
def rails_logger_exist?
|
62
|
+
defined?(Rails) && Rails.logger.present?
|
63
|
+
end
|
64
|
+
|
65
|
+
def use_rails_logger
|
66
|
+
@logger = Rails.logger
|
67
|
+
end
|
68
|
+
|
69
|
+
def use_default_logger
|
70
|
+
@logger = ActiveSupport::Logger.new(STDOUT)
|
71
|
+
end
|
46
72
|
end
|
47
73
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: icalia-sdk-event-notification
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Quintanilla
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: icalia-sdk-event-core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.1.
|
19
|
+
version: 0.1.13
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.1.
|
26
|
+
version: 0.1.13
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -117,7 +117,6 @@ extensions: []
|
|
117
117
|
extra_rdoc_files: []
|
118
118
|
files:
|
119
119
|
- lib/icalia-sdk-event-notification.rb
|
120
|
-
- lib/icalia-sdk-event-notification/event_triggering_record.rb
|
121
120
|
- lib/icalia-sdk-event-notification/notification.rb
|
122
121
|
- lib/icalia-sdk-event-notification/publisher.rb
|
123
122
|
- lib/icalia-sdk-event-notification/shoryuken.rb
|
@@ -1,108 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Icalia::Event::EventTriggeringRecord
|
4
|
-
#
|
5
|
-
# Defines methods & behavior of ActiveRecord models that trigger events to the
|
6
|
-
# Icalia Event Bus whenever something changes on it.
|
7
|
-
#
|
8
|
-
# The specifics on how the event is generated is left to the specifics of the
|
9
|
-
# app.
|
10
|
-
module Icalia::Event
|
11
|
-
module EventTriggeringRecord
|
12
|
-
extend ActiveSupport::Concern
|
13
|
-
|
14
|
-
included do
|
15
|
-
mattr_reader :delayed_icalia_event_publishing, default: true
|
16
|
-
mattr_reader :icalia_event_publishing_enabled, default: true
|
17
|
-
|
18
|
-
after_commit :publish_create_to_icalia_events, on: :create
|
19
|
-
after_commit :publish_update_to_icalia_events, on: :update
|
20
|
-
after_commit :publish_destroy_to_icalia_events, on: :destroy
|
21
|
-
|
22
|
-
delegate :icalia_event_class_name,
|
23
|
-
:icalia_event_publisher_class,
|
24
|
-
:icalia_events_publisher_method,
|
25
|
-
:delayed_icalia_event_publishing?,
|
26
|
-
:icalia_event_publishing_enabled?,
|
27
|
-
to: :class
|
28
|
-
end
|
29
|
-
|
30
|
-
module ClassMethods
|
31
|
-
def icalia_events_publisher_method
|
32
|
-
return :perform_now unless delayed_icalia_event_publishing?
|
33
|
-
:perform_later
|
34
|
-
end
|
35
|
-
|
36
|
-
def delayed_icalia_event_publishing?
|
37
|
-
delayed_icalia_event_publishing == true
|
38
|
-
end
|
39
|
-
|
40
|
-
def publish_to_icalia_events_immediately!
|
41
|
-
class_variable_set :@@delayed_icalia_event_publishing, false
|
42
|
-
end
|
43
|
-
|
44
|
-
def publish_to_icalia_events_later!
|
45
|
-
class_variable_set :@@delayed_icalia_event_publishing, true
|
46
|
-
end
|
47
|
-
|
48
|
-
def icalia_event_publishing_enabled?
|
49
|
-
icalia_event_publishing_enabled == true
|
50
|
-
end
|
51
|
-
|
52
|
-
def icalia_event_publishing_disabled?
|
53
|
-
!icalia_event_publishing_enabled?
|
54
|
-
end
|
55
|
-
|
56
|
-
def disable_icalia_event_publishing
|
57
|
-
class_variable_set :@@icalia_event_publishing_enabled, false
|
58
|
-
end
|
59
|
-
|
60
|
-
def enable_icalia_event_publishing
|
61
|
-
class_variable_set :@@icalia_event_publishing_enabled, true
|
62
|
-
end
|
63
|
-
|
64
|
-
def without_icalia_event_publishing(&_block)
|
65
|
-
disable_icalia_event_publishing if icalia_event_publishing_enabled?
|
66
|
-
result = yield self
|
67
|
-
enable_icalia_event_publishing if icalia_event_publishing_disabled?
|
68
|
-
result
|
69
|
-
ensure
|
70
|
-
enable_icalia_event_publishing if icalia_event_publishing_disabled?
|
71
|
-
end
|
72
|
-
|
73
|
-
def icalia_event_class_name
|
74
|
-
# The default behavior is to return the class name + 'Event':
|
75
|
-
"#{name}Event"
|
76
|
-
end
|
77
|
-
|
78
|
-
def icalia_event_publisher_class_name
|
79
|
-
"IcaliaEventPublishing::Publish#{icalia_event_class_name}Job"
|
80
|
-
end
|
81
|
-
|
82
|
-
def icalia_event_publisher_class
|
83
|
-
icalia_event_publisher_class_name.safe_constantize
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
private
|
88
|
-
|
89
|
-
def publish_to_icalia_events(action)
|
90
|
-
return unless icalia_event_publishing_enabled?
|
91
|
-
publisher_class = icalia_event_publisher_class
|
92
|
-
return unless publisher_class.present?
|
93
|
-
publisher_class.send icalia_events_publisher_method, action.to_s, self
|
94
|
-
end
|
95
|
-
|
96
|
-
def publish_create_to_icalia_events
|
97
|
-
publish_to_icalia_events 'created'
|
98
|
-
end
|
99
|
-
|
100
|
-
def publish_update_to_icalia_events
|
101
|
-
publish_to_icalia_events 'updated'
|
102
|
-
end
|
103
|
-
|
104
|
-
def publish_destroy_to_icalia_events
|
105
|
-
publish_to_icalia_events 'destroyed'
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|