Class: JobState

Inherits:
Object
  • Object
show all
Includes:
Observable
Defined in:
lib/gorgon/job_state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(total_files) ⇒ JobState

Returns a new instance of JobState.



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

def initialize total_files
  @total_files = total_files
  @remaining_files_count = total_files
  @failed_tests = []
  @crashed_hosts = []
  @hosts = {}

  if @remaining_files_count > 0
    @state = :starting
  else
    @state = :complete
  end
end

Instance Attribute Details

#crashed_hostsObject (readonly)

Returns the value of attribute crashed_hosts.



8
9
10
# File 'lib/gorgon/job_state.rb', line 8

def crashed_hosts
  @crashed_hosts
end

#remaining_files_countObject (readonly)

Returns the value of attribute remaining_files_count.



8
9
10
# File 'lib/gorgon/job_state.rb', line 8

def remaining_files_count
  @remaining_files_count
end

#stateObject (readonly)

Returns the value of attribute state.



8
9
10
# File 'lib/gorgon/job_state.rb', line 8

def state
  @state
end

#total_filesObject (readonly)

Returns the value of attribute total_files.



8
9
10
# File 'lib/gorgon/job_state.rb', line 8

def total_files
  @total_files
end

Instance Method Details

#cancelObject



65
66
67
68
69
70
# File 'lib/gorgon/job_state.rb', line 65

def cancel
  @remaining_files_count = 0
  @state = :cancelled
  changed
  notify_observers({})
end

#each_failed_testObject



72
73
74
75
76
# File 'lib/gorgon/job_state.rb', line 72

def each_failed_test
  @failed_tests.each do |test|
    yield test
  end
end

#each_running_fileObject



78
79
80
81
82
83
84
# File 'lib/gorgon/job_state.rb', line 78

def each_running_file
  @hosts.each do |hostname, host|
    host.each_running_file do |filename|
      yield hostname, filename
    end
  end
end

#failed_files_countObject



24
25
26
# File 'lib/gorgon/job_state.rb', line 24

def failed_files_count
  @failed_tests.count
end

#file_finished(payload) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/gorgon/job_state.rb', line 45

def file_finished payload
  raise_if_completed

  @remaining_files_count -= 1
  @state = :complete if @remaining_files_count == 0

  handle_failed_test payload if failed_test?(payload)

  @hosts[payload[:hostname]].file_finished payload[:worker_id], payload[:filename]

  changed
  notify_observers payload
end

#file_started(payload) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/gorgon/job_state.rb', line 32

def file_started payload
  raise_if_completed

  if @state == :starting
    @state = :running
  end

  file_started_update_host_state payload

  changed
  notify_observers payload
end

#finished_files_countObject



28
29
30
# File 'lib/gorgon/job_state.rb', line 28

def finished_files_count
  total_files - remaining_files_count
end

#gorgon_crash_message(payload) ⇒ Object



59
60
61
62
63
# File 'lib/gorgon/job_state.rb', line 59

def gorgon_crash_message payload
  @crashed_hosts << payload[:hostname]
  changed
  notify_observers payload
end

#is_job_cancelled?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/gorgon/job_state.rb', line 102

def is_job_cancelled?
  @state == :cancelled
end

#is_job_complete?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/gorgon/job_state.rb', line 98

def is_job_complete?
  @state == :complete
end

#total_running_hostsObject



86
87
88
# File 'lib/gorgon/job_state.rb', line 86

def total_running_hosts
  @hosts.size
end

#total_running_workersObject



90
91
92
93
94
95
96
# File 'lib/gorgon/job_state.rb', line 90

def total_running_workers
  result = 0
  @hosts.each do |hostname, host|
    result += host.total_running_workers
  end
  result
end