Class: Gorgon::JobState
- Inherits:
-
Object
- Object
- Gorgon::JobState
- Includes:
- Observable
- Defined in:
- lib/gorgon/job_state.rb
Instance Attribute Summary collapse
-
#crashed_hosts ⇒ Object
readonly
Returns the value of attribute crashed_hosts.
-
#remaining_files_count ⇒ Object
readonly
Returns the value of attribute remaining_files_count.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#total_files ⇒ Object
readonly
Returns the value of attribute total_files.
Instance Method Summary collapse
- #cancel ⇒ Object
- #each_failed_test ⇒ Object
- #each_running_file ⇒ Object
- #failed_files_count ⇒ Object
- #file_finished(payload) ⇒ Object
- #file_started(payload) ⇒ Object
- #finished_files_count ⇒ Object
- #gorgon_crash_message(payload) ⇒ Object
-
#initialize(total_files) ⇒ JobState
constructor
A new instance of JobState.
- #is_job_cancelled? ⇒ Boolean
- #is_job_complete? ⇒ Boolean
- #total_running_hosts ⇒ Object
- #total_running_workers ⇒ Object
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_hosts ⇒ Object (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_count ⇒ Object (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 |
#state ⇒ Object (readonly)
Returns the value of attribute state.
9 10 11 |
# File 'lib/gorgon/job_state.rb', line 9 def state @state end |
#total_files ⇒ Object (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
#cancel ⇒ Object
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_test ⇒ Object
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_file ⇒ Object
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_count ⇒ Object
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_count ⇒ Object
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 payload @crashed_hosts << payload[:hostname] changed notify_observers payload end |
#is_job_cancelled? ⇒ Boolean
103 104 105 |
# File 'lib/gorgon/job_state.rb', line 103 def is_job_cancelled? @state == :cancelled end |
#is_job_complete? ⇒ Boolean
99 100 101 |
# File 'lib/gorgon/job_state.rb', line 99 def is_job_complete? @state == :complete end |
#total_running_hosts ⇒ Object
87 88 89 |
# File 'lib/gorgon/job_state.rb', line 87 def total_running_hosts @hosts.size end |
#total_running_workers ⇒ Object
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 |