Sha256: affb74eedcc5b0bc176aaa549f1051cc1d4c2708b13d591cc3d9cb022c673eb1

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

require "parallel"

module Switchman
  module Parallel
    module UndumpableException
      def initialize(original)
        super
        @active_shards = original.instance_variable_get(:@active_shards)
        current_shard
      end
    end

    class QuietExceptionWrapper
      attr_accessor :name

      def initialize(name, wrapper)
        @name = name
        @wrapper = wrapper
      end

      def exception
        @wrapper.exception
      end
    end

    class UndumpableResult
      attr_reader :name

      def initialize(result)
        @name = result.inspect
      end

      def inspect
        "#<UndumpableResult:#{name}>"
      end
    end

    class ResultWrapper
      attr_reader :result

      def initialize(result)
        @result =
          begin
            Marshal.dump(result) && result
          rescue
            UndumpableResult.new(result)
          end
      end
    end

    class TransformingIO
      delegate_missing_to :@original_io

      def initialize(transformer, original_io)
        @transformer = transformer
        @original_io = original_io
      end

      def puts(*args)
        args.flatten.each { |arg| @original_io.puts @transformer.call(arg) }
      end
    end
  end
end

Parallel::UndumpableException.prepend(Switchman::Parallel::UndumpableException)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
switchman-3.6.7 lib/switchman/parallel.rb
switchman-3.6.6 lib/switchman/parallel.rb
switchman-3.6.5 lib/switchman/parallel.rb