Class: DatatrueClient::TestRun

Inherits:
Object
  • Object
show all
Defined in:
lib/datatrue_client/test_run.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TestRun



18
19
20
21
22
23
24
25
26
# File 'lib/datatrue_client/test_run.rb', line 18

def initialize(options={})
  @options = options
  @bridge = Bridge.new(options)

  @polling_timeout = options[:polling_timeout] || 60
  @polling_interval = options[:polling_interval] || 2

  create
end

Instance Attribute Details

#job_idObject (readonly)

Returns the value of attribute job_id.



8
9
10
# File 'lib/datatrue_client/test_run.rb', line 8

def job_id
  @job_id
end

#polling_intervalObject

Returns the value of attribute polling_interval.



9
10
11
# File 'lib/datatrue_client/test_run.rb', line 9

def polling_interval
  @polling_interval
end

#polling_timeoutObject

Returns the value of attribute polling_timeout.



9
10
11
# File 'lib/datatrue_client/test_run.rb', line 9

def polling_timeout
  @polling_timeout
end

#progressObject (readonly)

Returns the value of attribute progress.



8
9
10
# File 'lib/datatrue_client/test_run.rb', line 8

def progress
  @progress
end

#titleObject (readonly)

Returns the value of attribute title.



8
9
10
# File 'lib/datatrue_client/test_run.rb', line 8

def title
  @title
end

Instance Method Details

#poll_progress(print_progress = nil) ⇒ Object

Keeps querying progress until progress status is ‘complete`



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/datatrue_client/test_run.rb', line 36

def poll_progress(print_progress=nil)
  start_time = DateTime.now

  loop do
    res = query_progress
    @progress = progress_percentage(res)
    print_progress.call(@progress, res) if print_progress

    return res if res[:status] == 'completed'

    if elapsed_milliseconds(start_time, DateTime.now) >= @polling_timeout * 1000
      raise TimeoutError.new("Polling progress timed out after #{@polling_timeout} seconds")

      break
    else
      sleep @polling_interval
    end
  end
end

#query_progressHash

Queries test run progress



30
31
32
# File 'lib/datatrue_client/test_run.rb', line 30

def query_progress
  @bridge.test_run_progress(job_id)
end