Sha256: db403162f6faa5250b8ad78a0587c55e9eaa3cebf6cc22a50856bf283df1c9d7

Contents?: true

Size: 930 Bytes

Versions: 2

Compression:

Stored size: 930 Bytes

Contents

# frozen_string_literal: true

require "wsdirector/client"
require "wsdirector/protocols"

module WSDirector
  # Single client operator
  class Task
    attr_reader :global_holder, :client

    def initialize(config, global_holder:, result:)
      @ignore = config.fetch("ignore")
      @steps = config.fetch("steps")
      @global_holder = global_holder
      @result = result

      protocol_class = Protocols.get(config.fetch("protocol", "base"))
      @protocol = protocol_class.new(self)
    end

    def run
      connect!

      steps.each(&protocol)

      result.succeed
    rescue Error => e
      result.failed(e.message)
    end

    def sampled?(step)
      return true unless step["sample"]

      id, max = step["id"], step["sample"]

      result.track_sample(id, max)
    end

    private

    attr_reader :steps, :result, :protocol

    def connect!
      protocol.init_client(ignore: @ignore)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wsdirector-cli-0.5.0 lib/wsdirector/task.rb
wsdirector-cli-0.4.0 lib/wsdirector/task.rb