Class: CapistranoMulticonfigParallel::Job

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

Overview

class used to find application dependencies

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ApplicationHelper

parse_task_string, strip_characters_from_string

Methods included from StagesHelper

check_stage_path, checks_paths, fetch_stages, fetch_stages_paths, sorted_paths, stages_paths

Methods included from CoreHelper

app_configuration, app_debug_enabled?, app_logger, ask_confirm, check_terminal_tty, debug_websocket?, execute_with_rescue, find_config_type, find_loaded_gem, find_worker_log, force_confirmation, format_error, log_error, log_to_file, rescue_error, rescue_interrupt, show_warning, websocket_config, websocket_server_config

Methods included from InternalHelper

config_file, custom_commands, default_internal_config, detect_root, enable_main_log_file, find_env_multi_cap_root, internal_config_directory, internal_config_file, log_directory, main_log_file, root, try_detect_capfile

Constructor Details

#initialize(options) ⇒ Job

Returns a new instance of Job.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/capistrano_multiconfig_parallel/classes/job.rb', line 10

def initialize(options)
  @id = SecureRandom.uuid
  @app = options.fetch('app', '')
  @stage = options.fetch('stage', '')
  @action = options.fetch('action', '')
  @task_arguments = options.fetch('task_arguments', [])
  @env_options = {}
  @env_options = options.fetch('env_options', {}).each do |key, value|
    @env_options[key] = value if value.present? && !filtered_env_keys.include?(key)
  end
  @env_options["#{CapistranoMulticonfigParallel::ENV_KEY_JOB_ID}"] = @id
end

Instance Attribute Details

#action ⇒ Object

Returns the value of attribute action.



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

def action
  @action
end

#app ⇒ Object

Returns the value of attribute app.



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

def app
  @app
end

#env_options ⇒ Object

Returns the value of attribute env_options.



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

def env_options
  @env_options
end

#exit_status ⇒ Object

Returns the value of attribute exit_status.



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

def exit_status
  @exit_status
end

#id ⇒ Object

Returns the value of attribute id.



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

def id
  @id
end

#stage ⇒ Object

Returns the value of attribute stage.



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

def stage
  @stage
end

#status ⇒ Object

Returns the value of attribute status.



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

def status
  @status
end

#task_arguments ⇒ Object

Returns the value of attribute task_arguments.



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

def task_arguments
  @task_arguments
end

Instance Method Details

#build_capistrano_task(action = nil, env = []) ⇒ Object



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

def build_capistrano_task(action = nil, env = [])
  action = action.present? ? action : @action
  environment_options = setup_command_line_standard(env).join(' ')
  "cd #{detect_root} && RAILS_ENV=#{@stage}  bundle exec multi_cap #{job_stage} #{capistrano_action(action)}  #{environment_options}"
end

#capistrano_action(action = @action) ⇒ Object



35
36
37
38
# File 'lib/capistrano_multiconfig_parallel/classes/job.rb', line 35

def capistrano_action(action = @action)
  argv = @task_arguments.present? ? "[#{@task_arguments}]" : ''
  "#{action}#{argv}"
end

#execute_standard_deploy(action = nil) ⇒ Object



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

def execute_standard_deploy(action = nil)
  command = build_capistrano_task(action)
  puts("\n\n\n Executing '#{command}' \n\n\n .")
  sh("#{command}")
rescue => ex
  log_error(ex)
  execute_standard_deploy('deploy:rollback') if action.blank? && @name == 'deploy'
end

#filtered_env_keys ⇒ Object



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

def filtered_env_keys
  %w(STAGES ACTION)
end

#finished? ⇒ Boolean

Returns:

  • (Boolean)


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

def finished?
  status == 'finished'
end

#job_stage ⇒ Object



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

def job_stage
  @app.present? ? "#{@app}:#{@stage}" : "#{@stage}"
end

#setup_command_line_standard(*args) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/capistrano_multiconfig_parallel/classes/job.rb', line 40

def setup_command_line_standard(*args)
  array_options = []
  @env_options.each do |key, value|
    array_options << "#{key}=#{value}" if value.present?
  end
  array_options << '--trace' if app_debug_enabled?
  args.each do |arg|
    array_options << arg if arg.present?
  end
  array_options
end

#to_s ⇒ Object



67
68
69
# File 'lib/capistrano_multiconfig_parallel/classes/job.rb', line 67

def to_s
  to_json
end