class DirtyPipeline::Redis::Storage
Attributes
field[R]
store[R]
subject[R]
to_h[R]
Public Class Methods
new(subject, field)
click to toggle source
# File lib/dirty_pipeline/redis/storage.rb, line 33 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
Public Instance Methods
commit!(event)
click to toggle source
# File lib/dirty_pipeline/redis/storage.rb, line 50 def commit!(event) store["status"] = event.destination if event.success? store["state"].merge!(event.changes) unless event.changes.to_h.empty? error = {} error = event.error.to_h unless event.error.to_h.empty? store["errors"][event.id] = error data = {} data = event.data.to_h unless event.data.to_h.empty? store["events"][event.id] = data save! end
find_event(event_id)
click to toggle source
# File lib/dirty_pipeline/redis/storage.rb, line 64 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!()
click to toggle source
# File lib/dirty_pipeline/redis/storage.rb, line 41 def reset! reset save! end
status()
click to toggle source
# File lib/dirty_pipeline/redis/storage.rb, line 46 def status store["status"] end
Private Instance Methods
reset()
click to toggle source
# File lib/dirty_pipeline/redis/storage.rb, line 81 def reset @store = subject.send( "#{field}=", { "status" => nil, "state" => {}, "events" => {}, "errors" => {} } ) end
save!()
click to toggle source
FIXME: save! - configurable method
# File lib/dirty_pipeline/redis/storage.rb, line 76 def save! subject.send("#{field}=", store) subject.save! end
valid_store?()
click to toggle source
# File lib/dirty_pipeline/redis/storage.rb, line 71 def valid_store? (store.keys & %w(status events errors state)).size.eql?(4) end