Class: Gorgon::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.



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

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.



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

def crashed_hosts
  @crashed_hosts
end

#remaining_files_countObject (readonly)

Returns the value of attribute remaining_files_count.



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

def remaining_files_count
  @remaining_files_count
end

#stateObject (readonly)

Returns the value of attribute state.



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

def state
  @state
end

#total_filesObject (readonly)

Returns the value of attribute total_files.



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

def total_files
  @total_files
end

Instance Method Details

#cancelObject



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

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

#each_failed_testObject



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

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

#each_running_fileObject



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

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

#failed_files_countObject



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

def failed_files_count
  @failed_tests.count
end

#file_finished(payload) ⇒ Object



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

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



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

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



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

def finished_files_count
  total_files - remaining_files_count
end

#gorgon_crash_message(payload) ⇒ Object



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

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

#is_job_cancelled?Boolean

Returns:

  • (Boolean)


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

def is_job_cancelled?
  @state == :cancelled
end

#is_job_complete?Boolean

Returns:

  • (Boolean)


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

def is_job_complete?
  @state == :complete
end

#total_running_hostsObject



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

def total_running_hosts
  @hosts.size
end

#total_running_workersObject



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

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