Class: CapistranoMulticonfigParallel::Job

Inherits:
Object
  • Object
show all
Includes:
ApplicationHelper
Defined in:
lib/capistrano_multiconfig_parallel/classes/job.rb

Overview

class used for defining the job class

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ApplicationHelper

action_confirmed?, fetch_parsed_string, fetch_remaining_arguments, find_remaining_args, get_question_details, msg_for_stdin?, msg_for_task?, parse_task_string, percent_of, regex_last_match, setup_command_line_standard, wrap_string

Methods included from CapistranoHelper

env_key_format, env_prefix, filtered_env_keys_format, trace_flag

Methods included from GemHelper

fetch_gem_version, find_loaded_gem, find_loaded_gem_property, get_parsed_version, verify_gem_version

Methods included from StagesHelper

check_stage_path, checks_paths, fetch_stages_paths, sorted_paths, stages, stages_paths

Methods included from ParseHelper

check_hash_set, check_numeric, strip_characters_from_string, value_is_array?, verify_array_of_strings, verify_empty_options, warn_array_without_strings

Methods included from CoreHelper

app_debug_enabled?, ask_confirm, ask_stdout_confirmation, check_terminal_tty, debug_websocket?, error_filtered?, execute_with_rescue, find_worker_log, force_confirmation, format_error, log_error, log_output_error, log_to_file, multi_fetch_argv, print_to_log_file, rescue_error, rescue_interrupt, setup_filename_logger, setup_logger_formatter, show_warning, terminal_actor, terminal_errors?, websocket_config, websocket_server_config

Methods included from InternalHelper

arg_is_in_default_config?, check_file, config_file, create_log_file, custom_commands, default_config_keys, default_internal_config, default_internal_configuration_params, detect_root, enable_main_log_file, fail_capfile_not_found, fetch_default_internal_config, find_config_type, find_env_multi_cap_root, find_file_in_directory, internal_config_directory, internal_config_file, log_directory, main_log_file, multi_level_prop, pathname_is_root?, pwd_directory, pwd_parent_dir, root, setup_default_configuration_types, sliced_default_config, try_detect_capfile

Constructor Details

#initialize(application, options) ⇒ Job

Returns a new instance of Job.



18
19
20
21
22
# File 'lib/capistrano_multiconfig_parallel/classes/job.rb', line 18

def initialize(application, options)
  @options = options.stringify_keys
  @application = application
  @manager = @application.manager
end

Instance Attribute Details

#exit_status=(value) ⇒ Object (writeonly)

Sets the attribute exit_status

Parameters:

  • value

    the value to set the attribute exit_status to.



9
10
11
# File 'lib/capistrano_multiconfig_parallel/classes/job.rb', line 9

def exit_status=(value)
  @exit_status = value
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/capistrano_multiconfig_parallel/classes/job.rb', line 8

def options
  @options
end

#status=(value) ⇒ Object (writeonly)

Sets the attribute status

Parameters:

  • value

    the value to set the attribute status to.



9
10
11
# File 'lib/capistrano_multiconfig_parallel/classes/job.rb', line 9

def status=(value)
  @status = value
end

Instance Method Details

#commandObject



28
29
30
# File 'lib/capistrano_multiconfig_parallel/classes/job.rb', line 28

def command
  @command ||= CapistranoMulticonfigParallel::JobCommand.new(self)
end

#crashed?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/capistrano_multiconfig_parallel/classes/job.rb', line 97

def crashed?
  worker_died? || failed? || dead? || exit_status.present?
end

#dead?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/capistrano_multiconfig_parallel/classes/job.rb', line 101

def dead?
  status.present? && status.to_s.downcase == 'dead'
end

#env_variableObject



24
25
26
# File 'lib/capistrano_multiconfig_parallel/classes/job.rb', line 24

def env_variable
  CapistranoMulticonfigParallel::ENV_KEY_JOB_ID
end

#failed?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/capistrano_multiconfig_parallel/classes/job.rb', line 89

def failed?
  ['deploy:failed'].include?(status)
end

#finished?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/capistrano_multiconfig_parallel/classes/job.rb', line 85

def finished?
  status == 'finished'
end

#idObject



64
65
66
# File 'lib/capistrano_multiconfig_parallel/classes/job.rb', line 64

def id
  @id ||= @options.fetch('id', SecureRandom.uuid)
end

#rolling_back?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/capistrano_multiconfig_parallel/classes/job.rb', line 93

def rolling_back?
  ['deploy:rollback'].include?(action)
end

#row_sizeObject



46
47
48
49
50
51
# File 'lib/capistrano_multiconfig_parallel/classes/job.rb', line 46

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

#terminal_env_variablesObject



32
33
34
# File 'lib/capistrano_multiconfig_parallel/classes/job.rb', line 32

def terminal_env_variables
  setup_command_line(filtered_keys: [env_variable])
end

#terminal_rowObject



36
37
38
39
40
41
42
43
44
# File 'lib/capistrano_multiconfig_parallel/classes/job.rb', line 36

def terminal_row
  [
    { value: id.to_s },
    { value: wrap_string(job_stage) },
    { value: wrap_string(capistrano_action) },
    { value: terminal_env_variables.map { |str| wrap_string(str) }.join("\n") },
    { value: wrap_string(worker_state) }
  ]
end

#to_jsonObject



109
110
111
112
113
114
115
# File 'lib/capistrano_multiconfig_parallel/classes/job.rb', line 109

def to_json
  hash = {}
  %w(id app stage action task_arguments env_options status exit_status).each do |key|
    hash[key] = send(key)
  end
  hash
end

#workerObject



53
54
55
56
# File 'lib/capistrano_multiconfig_parallel/classes/job.rb', line 53

def worker
  return unless @manager.alive?
  @manager.get_worker_for_job(id)
end

#worker_died?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/capistrano_multiconfig_parallel/classes/job.rb', line 105

def worker_died?
  !worker.alive?
end

#worker_stateObject



58
59
60
61
62
# File 'lib/capistrano_multiconfig_parallel/classes/job.rb', line 58

def worker_state
  worker_obj = worker
  default = status.to_s.upcase.red
  worker_obj.present? && worker_obj.alive? ? worker_obj.worker_state : default
end