Class: WSDirector::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/wsdirector/task.rb

Overview

Single client operator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, id:, global_holder:, result:, scale:, logger:, colorize: false) ⇒ Task

Returns a new instance of Task.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/wsdirector/task.rb', line 11

def initialize(config, id:, global_holder:, result:, scale:, logger:, colorize: false)
  @id = id
  @logger = logger
  @ignore = config.fetch("ignore")
  @steps = config.fetch("steps")
  @connection_options = config.fetch("connection_options").transform_keys(&:to_sym)
  @global_holder = global_holder
  @result = result

  protocol_class = Protocols.get(config.fetch("protocol", "base"))
  @protocol = protocol_class.new(self, scale:, logger:, id:, color: color_for_id(id, colorize))
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



9
10
11
# File 'lib/wsdirector/task.rb', line 9

def client
  @client
end

#global_holderObject (readonly)

Returns the value of attribute global_holder.



9
10
11
# File 'lib/wsdirector/task.rb', line 9

def global_holder
  @global_holder
end

Instance Method Details

#run(url) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/wsdirector/task.rb', line 24

def run(url)
  connect!(url, **@connection_options)

  steps.each(&protocol)

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

#sampled?(step) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
# File 'lib/wsdirector/task.rb', line 34

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

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

  result.track_sample(id, max)
end