Class: PubSubModelSync::Payload
- Inherits:
-
Object
- Object
- PubSubModelSync::Payload
- Defined in:
- lib/pub_sub_model_sync/payload.rb
Defined Under Namespace
Classes: MissingInfo
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#info ⇒ Object
readonly
Returns the value of attribute info.
Class Method Summary collapse
-
.from_payload_data(data) ⇒ Object
convert payload data into Payload.
Instance Method Summary collapse
- #action ⇒ Object
-
#cache_settings ⇒ Object
Attributes to always be delivered after cache optimization.
- #exclude_data_attrs(attr_keys) ⇒ Object
-
#initialize(data, info, headers = {}) ⇒ Payload
constructor
A new instance of Payload.
- #klass ⇒ Object
- #mode ⇒ Object
- #ordering_key ⇒ Object
-
#process ⇒ Object
Process payload data (If error will call on_error_processing callback).
-
#process! ⇒ Object
Process payload data (If error will raise exception and wont call on_error_processing callback).
-
#publish ⇒ Object
Publish payload to pubsub (If error will call on_error_publish callback).
-
#publish! ⇒ Object
Publish payload to pubsub (If error will raise exception and wont call on_error_publish callback).
-
#retry_publish! ⇒ Object
allows to retry publishing a failed payload.
-
#to_h ⇒ Object
Hash: payload data.
- #uuid ⇒ Object
Constructor Details
#initialize(data, info, headers = {}) ⇒ Payload
Returns a new instance of Payload.
33 34 35 36 37 38 39 |
# File 'lib/pub_sub_model_sync/payload.rb', line 33 def initialize(data, info, headers = {}) @data = data.deep_symbolize_keys @info = info.deep_symbolize_keys @headers = headers.deep_symbolize_keys build_headers validate! end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/pub_sub_model_sync/payload.rb', line 6 def data @data end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
6 7 8 |
# File 'lib/pub_sub_model_sync/payload.rb', line 6 def headers @headers end |
#info ⇒ Object (readonly)
Returns the value of attribute info.
6 7 8 |
# File 'lib/pub_sub_model_sync/payload.rb', line 6 def info @info end |
Class Method Details
.from_payload_data(data) ⇒ Object
convert payload data into Payload
109 110 111 112 |
# File 'lib/pub_sub_model_sync/payload.rb', line 109 def self.from_payload_data(data) data = data.symbolize_keys new(data[:data], data[:info] || data[:attributes], data[:headers]) end |
Instance Method Details
#action ⇒ Object
50 51 52 |
# File 'lib/pub_sub_model_sync/payload.rb', line 50 def action info[:action].to_sym end |
#cache_settings ⇒ Object
Attributes to always be delivered after cache optimization
103 104 105 |
# File 'lib/pub_sub_model_sync/payload.rb', line 103 def cache_settings headers[:cache] end |
#exclude_data_attrs(attr_keys) ⇒ Object
98 99 100 |
# File 'lib/pub_sub_model_sync/payload.rb', line 98 def exclude_data_attrs(attr_keys) @data = data.except(*attr_keys) end |
#klass ⇒ Object
46 47 48 |
# File 'lib/pub_sub_model_sync/payload.rb', line 46 def klass info[:klass].to_s end |
#mode ⇒ Object
54 55 56 |
# File 'lib/pub_sub_model_sync/payload.rb', line 54 def mode (info[:mode] || :model).to_sym end |
#ordering_key ⇒ Object
62 63 64 |
# File 'lib/pub_sub_model_sync/payload.rb', line 62 def ordering_key headers[:ordering_key] end |
#process ⇒ Object
Process payload data
(If error will call on_error_processing callback)
75 76 77 78 |
# File 'lib/pub_sub_model_sync/payload.rb', line 75 def process publisher = PubSubModelSync::MessageProcessor.new(self) publisher.process end |
#process! ⇒ Object
Process payload data
(If error will raise exception and wont call on_error_processing callback)
68 69 70 71 |
# File 'lib/pub_sub_model_sync/payload.rb', line 68 def process! publisher = PubSubModelSync::MessageProcessor.new(self) publisher.process! end |
#publish ⇒ Object
Publish payload to pubsub
(If error will call on_error_publish callback)
88 89 90 |
# File 'lib/pub_sub_model_sync/payload.rb', line 88 def publish PubSubModelSync::MessagePublisher.publish(self) end |
#publish! ⇒ Object
Publish payload to pubsub
(If error will raise exception and wont call on_error_publish callback)
82 83 84 |
# File 'lib/pub_sub_model_sync/payload.rb', line 82 def publish! PubSubModelSync::MessagePublisher.publish!(self) end |
#retry_publish! ⇒ Object
allows to retry publishing a failed payload
93 94 95 |
# File 'lib/pub_sub_model_sync/payload.rb', line 93 def retry_publish! PubSubModelSync::MessagePublisher.connector_publish(self) end |
#to_h ⇒ Object
Returns Hash: payload data.
42 43 44 |
# File 'lib/pub_sub_model_sync/payload.rb', line 42 def to_h { data: data.clone, info: info.clone, headers: headers.clone } end |
#uuid ⇒ Object
58 59 60 |
# File 'lib/pub_sub_model_sync/payload.rb', line 58 def uuid headers[:uuid] end |