Sha256: f168e3bec5645c8d6a4ba82b75fad41d8985cffd5437c1c426fb040e234d761e

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

require 'pp'
require 'securerandom'

module Clomp
  class Executor
    class << self
      # _self = operation
      #
      def [](result = {}, options, _self:)
        result['tracks'].each_with_index do |track, i|
          
          break if break?(result['tracks'].select {|track|  track.executed? }, i)
          
          next if _self.successful? && track.left_track?
          next if _self.failed? && track.right_track?
          
          _callable_object = Callable[track, options, _self]
          
          raise Errors::TrackNotDefined, "Please define the track in your operation/service: #{track.name} in #{_callable_object.class}" unless _callable_object.respond_to?(track.name)
          
          _track = track.exec!(_callable_object, options)
        end
        
        _self
      end
      
      def break?(tracks, index)
        track = index > 0 && tracks[index -1] || Track.new(name: SecureRandom.hex(5)).tap {|track| track.mark_as_success! && track.executed = true}
        
        return true if track.right_track? && track.failure? && track.track_options[:fail_fast]
        
        return true if track.left_track? && track.track_options[:fail_fast]
        
        !track.track_options[:pass_fast].nil?
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
clomp-1.0.0 lib/clomp/executor.rb