Class: Inferno::Repositories::TestRuns

Inherits:
Repository
  • Object
show all
Defined in:
lib/inferno/repositories/test_runs.rb

Defined Under Namespace

Classes: Model

Instance Method Summary collapse

Methods inherited from Repository

#add_non_db_entities, #create, db, #db_params, #entity_class, #entity_class_name, #find, #handle_non_db_params, #non_db_params, table_name, #update

Instance Method Details

#active_test_run_for_session?(test_session_id) ⇒ Boolean

Returns:

  • (Boolean)


127
128
129
130
131
132
# File 'lib/inferno/repositories/test_runs.rb', line 127

def active_test_run_for_session?(test_session_id)
  self.class::Model
    .where(test_session_id:)
    .exclude(status: 'done')
    .count.positive?
end

#build_entity(params) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/inferno/repositories/test_runs.rb', line 16

def build_entity(params)
  super.tap do |test_run|
    test_run&.results&.map! do |result|
      result.is_a?(Entities::Result) ? result : Entities::Result.new(result)
    end
  end
end

#find_latest_waiting_by_identifier(identifier) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/inferno/repositories/test_runs.rb', line 35

def find_latest_waiting_by_identifier(identifier)
  test_run_hash =
    self.class::Model
      .where(status: 'waiting')
      .where(identifier:)
      .where { wait_timeout >= Time.now }
      .order(Sequel.desc(:updated_at))
      .limit(1)
      .to_a
      &.first
      &.to_hash

  return nil if test_run_hash.nil?

  build_entity(test_run_hash)
end

#json_serializer_optionsObject



8
9
10
11
12
13
14
# File 'lib/inferno/repositories/test_runs.rb', line 8

def json_serializer_options
  {
    include: {
      results: results_repo.json_serializer_options
    }
  }
end

#last_test_run(test_session_id) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/inferno/repositories/test_runs.rb', line 52

def last_test_run(test_session_id)
  test_run_hash =
    self.class::Model
      .where(test_session_id:)
      .order(Sequel.desc(:updated_at))
      .limit(1)
      .to_a
      .map { |record| record.to_json_data.deep_symbolize_keys! }
      &.first
      &.to_hash

  return nil if test_run_hash.nil?

  build_entity(test_run_hash)
end

#mark_as_cancelling(test_run_id) ⇒ Object



98
99
100
# File 'lib/inferno/repositories/test_runs.rb', line 98

def mark_as_cancelling(test_run_id)
  update(test_run_id, status: 'cancelling')
end

#mark_as_done(test_run_id) ⇒ Object



76
77
78
# File 'lib/inferno/repositories/test_runs.rb', line 76

def mark_as_done(test_run_id)
  update(test_run_id, status: 'done')
end

#mark_as_no_longer_waiting(test_run_id) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/inferno/repositories/test_runs.rb', line 89

def mark_as_no_longer_waiting(test_run_id)
  update(
    test_run_id,
    status: 'queued',
    identifier: nil,
    wait_timeout: nil
  )
end

#mark_as_running(test_run_id) ⇒ Object



72
73
74
# File 'lib/inferno/repositories/test_runs.rb', line 72

def mark_as_running(test_run_id)
  update(test_run_id, status: 'running')
end

#mark_as_waiting(test_run_id, identifier, timeout) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/inferno/repositories/test_runs.rb', line 80

def mark_as_waiting(test_run_id, identifier, timeout)
  update(
    test_run_id,
    status: 'waiting',
    identifier:,
    wait_timeout: Time.now + timeout.seconds
  )
end

#results_for_test_run(test_run_id) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/inferno/repositories/test_runs.rb', line 24

def results_for_test_run(test_run_id)
  test_run_hash =
    self.class::Model
      .find(id: test_run_id)
      .to_json_data(json_serializer_options)
      .deep_symbolize_keys!

  test_run_hash[:results]
    .map! { |result| results_repo.build_entity(result) }
end

#status_for_test_run(id) ⇒ Object



68
69
70
# File 'lib/inferno/repositories/test_runs.rb', line 68

def status_for_test_run(id)
  self.class::Model.where(id:).get(:status)
end