Class: DirtyPipeline::Storage
- Inherits:
-
Object
- Object
- DirtyPipeline::Storage
- Defined in:
- lib/dirty_pipeline/storage.rb
Overview
Storage structure {
status: :errored,
state: {
field: "value",
},
errors: {
"<event_id>": {
error: "RuPost::API::Error",
error_message: "Timeout error",
created_at: 2018-01-01T13:22Z
},
},
events: {
<event_id>: {
transition: "Create",
args: ...,
changes: ...,
created_at: ...,
updated_at: ...,
attempts_count: 2,
},
<event_id>: {...},
}
}
Defined Under Namespace
Classes: InvalidPipelineStorage
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#store ⇒ Object
(also: #to_h)
readonly
Returns the value of attribute store.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Instance Method Summary collapse
- #commit!(event) ⇒ Object
- #find_event(event_id) ⇒ Object
-
#initialize(subject, field) ⇒ Storage
constructor
A new instance of Storage.
- #reset! ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(subject, field) ⇒ Storage
Returns a new instance of Storage.
32 33 34 35 36 37 38 |
# File 'lib/dirty_pipeline/storage.rb', line 32 def initialize(subject, field) @subject = subject @field = field @store = subject.send(@field).to_h reset if @store.empty? raise InvalidPipelineStorage, store unless valid_store? end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
30 31 32 |
# File 'lib/dirty_pipeline/storage.rb', line 30 def field @field end |
#store ⇒ Object (readonly) Also known as: to_h
Returns the value of attribute store.
30 31 32 |
# File 'lib/dirty_pipeline/storage.rb', line 30 def store @store end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
30 31 32 |
# File 'lib/dirty_pipeline/storage.rb', line 30 def subject @subject end |
Instance Method Details
#commit!(event) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/dirty_pipeline/storage.rb', line 49 def commit!(event) store["status"] = event.destination if event.destination store["state"].merge!(event.changes) unless event.changes.to_h.empty? store["errors"][event.id] = event.error unless event.error.to_h.empty? store["events"][event.id] = event.data unless event.data.to_h.empty? save! end |
#find_event(event_id) ⇒ Object
57 58 59 60 |
# File 'lib/dirty_pipeline/storage.rb', line 57 def find_event(event_id) return unless (found_event = store.dig("events", event_id)) Event.new(data: found_event, error: store.dig("errors", event_id)) end |
#reset! ⇒ Object
40 41 42 43 |
# File 'lib/dirty_pipeline/storage.rb', line 40 def reset! reset save! end |
#status ⇒ Object
45 46 47 |
# File 'lib/dirty_pipeline/storage.rb', line 45 def status store["status"] end |