class CapistranoMulticonfigParallel::Job
class used for defining the job class
Attributes
application[R]
bundler_check_status[RW]
bundler_status[RW]
exit_status[W]
manager[R]
new_jobs_dispatched[W]
options[R]
status[W]
will_dispatch_new_job[W]
Public Class Methods
new(application, options)
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 15 def initialize(application, options) @options = options.stringify_keys @application = application @manager = @application.manager @gitflow ||= command.gitflow_enabled? end
Public Instance Methods
bundler_check_terminal_row()
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 59 def bundler_check_terminal_row [ { value: wrap_string(id.to_s) }, { value: wrap_string(File.basename(job.job_path)) }, { value: wrap_string("bundle check || bundle install") }, { value: wrap_coloured_string(bundler_check_status.to_s, color: bundler_check_status_colour) } ] end
bundler_terminal_row()
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 68 def bundler_terminal_row [ { value: wrap_string(id.to_s) }, { value: wrap_string(job_stage_for_terminal) }, { value: wrap_string("Setting up gems..") }, { value: terminal_env_variables.map { |str| wrap_string(str) }.join("\n") }, { value: wrap_coloured_string(status.to_s, color: :green) } ] end
command()
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 35 def command @command ||= CapistranoMulticonfigParallel::JobCommand.new(self) end
crashed?()
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 161 def crashed? worker_died? || failed? || exit_status.present? end
dead?()
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 165 def dead? status.present? && status.to_s.downcase == 'dead' end
env_variable()
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 31 def env_variable CapistranoMulticonfigParallel.env_job_key_id end
failed?()
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 137 def failed? ['deploy:failed'].include?(status) end
finished?()
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 133 def finished? status == 'finished' end
id()
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 100 def id @id ||= @options.fetch('id', SecureRandom.uuid) end
inspect()
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 177 def inspect to_s end
mark_for_dispatching_new_job()
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 145 def mark_for_dispatching_new_job return if rolling_back? self.will_dispatch_new_job = new_jobs_dispatched.size + 1 end
marked_for_dispatching_new_job?()
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 150 def marked_for_dispatching_new_job? will_dispatch_new_job.to_i != new_jobs_dispatched.size end
method_missing(sym, *args, &block)
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 193 def method_missing(sym, *args, &block) command.public_send(sym, *args, &block) end
new_jobs_dispatched_finished?()
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 154 def new_jobs_dispatched_finished? if marked_for_dispatching_new_job? sleep(0.1) until will_dispatch_new_job.to_i == new_jobs_dispatched.size end true end
respond_to_missing?(method_name, include_private = false)
click to toggle source
Calls superclass method
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 197 def respond_to_missing?(method_name, include_private = false) command.public_methods.include?(method_name) || super end
rolling_back?()
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 141 def rolling_back? ['deploy:rollback'].include?(action) end
row_size()
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 78 def row_size longest_hash = terminal_row.max_by do |hash| hash[:value].size end (longest_hash[:value].size.to_f / 80.0).ceil end
save_stderr_error(data)
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 22 def save_stderr_error(data) return unless development_debug? return unless @manager.alive? stderr_buffer.rewind old_data = stderr_buffer.read.dup new_data = old_data.to_s + data stderr_buffer.write(new_data) if ['aborted!', 'Terminating', 'Error'].any? { |word| new_data.include?(word) } end
setup_additional_env_variables(value)
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 128 def setup_additional_env_variables(value) value["#{env_variable}"] = id #value["capistrano_version"] = job_capistrano_version end
terminal_env_variables()
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 39 def terminal_env_variables setup_command_line(filtered_keys: [env_variable]) end
terminal_row()
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 43 def terminal_row if bundler_check_status bundler_check_terminal_row elsif bundler_status bundler_terminal_row else [ { value: wrap_string(id.to_s) }, { value: wrap_string(job_stage_for_terminal) }, { value: wrap_string(capistrano_action) }, { value: terminal_env_variables.map { |str| wrap_string(str) }.join("\n") }, { value: wrap_coloured_string(*worker_state) } ] end end
to_json()
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 185 def to_json hash = {} %w(id app stage action task_arguments env_options status exit_status bundler_status will_dispatch_new_job new_jobs_dispatched).each do |key| hash[key] = send(key).inspect end hash end
to_s()
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 181 def to_s JSON.generate(to_json) end
work_done?()
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 173 def work_done? new_jobs_dispatched_finished? && (finished? || crashed?) end
worker()
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 85 def worker return unless @manager.alive? @manager.get_worker_for_job(id) end
worker_died?()
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 169 def worker_died? dead? || worker == nil || worker.dead? end
worker_state()
click to toggle source
# File lib/capistrano_multiconfig_parallel/classes/job.rb, line 90 def worker_state worker_obj = worker default = status.to_s.upcase if worker_died? [default, color: :red] else [worker_obj.worker_state, color: worker.state_colour] end end