lib/dirty_pipeline/base.rb in dirty_pipeline-0.8.3 vs lib/dirty_pipeline/base.rb in dirty_pipeline-0.9.0
- old
+ new
@@ -40,16 +40,20 @@
@storage = Storage.new(subject, self.class.pipeline_storage)
@railway = Railway.new(subject, @uuid)
@status = Status.success(subject)
end
- def find_transition(name)
- self.class.transitions_map.fetch(name.to_s).tap do |from:, **kwargs|
- next unless railway.operation.eql?(:call)
- next if from == Array(storage.status)
- next if from.include?(storage.status.to_s)
- raise InvalidTransition, "from `#{storage.status}` by `#{name}`"
+ def find_transition!(event)
+ tname = event.transition
+ event.source = storage.status
+ self.class.transitions_map.fetch(tname.to_s).tap do |from:, **kwargs|
+ next unless railway.operation.eql?("call")
+ next if from == Array(event.source)
+ next if from.include?(event.source.to_s)
+ raise InvalidTransition, "from `#{event.source}` by `#{tname}`"
+ end.tap do |to:, **|
+ event.destination = to if railway.operation.eql?("call")
end
end
def reset!
railway.clear!
@@ -126,16 +130,18 @@
private
def execute(event, attempt_retry: false)
attempt_retry ? event.attempt_retry! : event.start!
- # dispatch event?
- Transaction.new(self, event).call do |destination, action, *args|
+ Transaction.new(self, event).call do |action, *args|
state_changes = process_action(action, event, *args)
+
event.assign_changes(state_changes)
+ event.complete if event.start?
+
next if status.failure?
- Success(event, destination)
+ Success(event)
end
call_next
self
end
@@ -175,11 +181,10 @@
def Failure(event, cause, type:)
event.failure!
@status = Status.failure(cause, tag: type)
end
- def Success(event, destination)
- event.complete(destination)
+ def Success(event)
@status = Status.success(subject)
end
end
end