Class: CapistranoMulticonfigParallel::BaseManager

Inherits:
Object
  • Object
show all
Includes:
Celluloid, Celluloid::Logger
Defined in:
lib/capistrano_multiconfig_parallel/helpers/base_manager.rb

Overview

finds app dependencies, shows menu and delegates jobs to celluloid manager rubocop:disable ClassLength

Direct Known Subclasses

MultiAppManager, SingleAppManager

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cap_app, top_level_tasks, stages) ⇒ BaseManager

Returns a new instance of BaseManager.



11
12
13
14
15
16
17
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 11

def initialize(cap_app, top_level_tasks, stages)
  @cap_app = cap_app
  @top_level_tasks = top_level_tasks
  @stages = stages
  @jobs = []
  CapistranoMulticonfigParallel.enable_logging
end

Instance Attribute Details

#applicationObject

Returns the value of attribute application.



9
10
11
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9

def application
  @application
end

#argsObject

Returns the value of attribute args.



9
10
11
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9

def args
  @args
end

#argvObject

Returns the value of attribute argv.



9
10
11
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9

def argv
  @argv
end

#conditionObject

Returns the value of attribute condition.



9
10
11
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9

def condition
  @condition
end

#default_stageObject

Returns the value of attribute default_stage.



9
10
11
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9

def default_stage
  @default_stage
end

#depsObject

Returns the value of attribute deps.



9
10
11
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9

def deps
  @deps
end

#job_registered_conditionObject

Returns the value of attribute job_registered_condition.



9
10
11
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9

def job_registered_condition
  @job_registered_condition
end

#jobsObject

Returns the value of attribute jobs.



9
10
11
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9

def jobs
  @jobs
end

#managerObject

Returns the value of attribute manager.



9
10
11
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9

def manager
  @manager
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9

def name
  @name
end

#original_argvObject

Returns the value of attribute original_argv.



9
10
11
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9

def original_argv
  @original_argv
end

#stageObject

Returns the value of attribute stage.



9
10
11
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 9

def stage
  @stage
end

Instance Method Details

#can_start?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 19

def can_start?
  @top_level_tasks.size > 1 && (stages.include?(@top_level_tasks.first) || custom_command?) && ENV[CapistranoMulticonfigParallel::ENV_KEY_JOB_ID].blank?
end

#can_tag_staging?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 114

def can_tag_staging?
  using_git? && wants_deploy_production? && tag_staging_exists? && worker_environments.include?('staging')
end

#check_before_startingObject



67
68
69
70
71
72
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 67

def check_before_starting
  CapistranoMulticonfigParallel.configuration_valid?
  @default_stage = CapistranoMulticonfigParallel.configuration.development_stages.present? ? CapistranoMulticonfigParallel.configuration.development_stages.first : 'development'
  @condition = Celluloid::Condition.new
  @manager = CapistranoMulticonfigParallel::CelluloidManager.new(Actor.current)
end

#check_giflow_tasks(*tasks) ⇒ Object



99
100
101
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 99

def check_giflow_tasks(*tasks)
  tasks.all? {|t| t.present? && t.prerequisites.present? }
end

#check_multi_stages(stages) ⇒ Object



118
119
120
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 118

def check_multi_stages(stages)
  can_tag_staging? ? stages.reject { |u| u == 'production' } : stages
end

#collect_jobs(options = {}, &block) ⇒ Object



74
75
76
77
78
79
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 74

def collect_jobs(options = {}, &block)
  options = prepare_options(options)
  block.call(options) if block_given?
rescue => e
  raise [e, e.backtrace].inspect
end

#configurationObject



40
41
42
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 40

def configuration
  CapistranoMulticonfigParallel.configuration
end

#confirmation_applies_to_all_workers?Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 145

def confirmation_applies_to_all_workers?
  CapistranoMulticonfigParallel.configuration.apply_stage_confirmation.all? { |e| worker_environments.include?(e) }
end

#custom_command?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 23

def custom_command?
  @top_level_tasks.first == 'ensure_stage' && !stages.include?(@top_level_tasks.second) && !stages.include?(@top_level_tasks.first) && custom_commands.values.include?(@top_level_tasks.second)
end

#custom_commandsObject



27
28
29
30
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 27

def custom_commands
  key = multi_apps? ? CapistranoMulticonfigParallel::MULTI_KEY : CapistranoMulticonfigParallel::SINGLE_KEY
  CapistranoMulticonfigParallel::CUSTOM_COMMANDS[key]
end

#deploy_app(options = {}) ⇒ Object



122
123
124
125
126
127
128
129
130
131
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 122

def deploy_app(options = {})
  options = options.stringify_keys
  app = options['app'].is_a?(Hash) ? options['app'] : { 'app' => options['app'] }
  branch = @branch_backup.present? ? @branch_backup : @argv['BRANCH'].to_s
  call_task_deploy_app({
    branch: branch,
    app: app,
    action: options['action']
  }.reverse_merge(options))
end

#executes_deploy_stages?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 32

def executes_deploy_stages?
  @name == custom_commands[:stages]
end

#fetch_multi_stagesObject



103
104
105
106
107
108
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 103

def fetch_multi_stages
  stages = @argv['STAGES'].blank? ? '' : @argv['STAGES']
  @argv = @argv['STAGES'].present? ? @argv.except('STAGES') : @argv
  stages = parse_inputted_value(value: stages).split(',').compact if stages.present?
  stages.present? ? stages : [@default_stage]
end

#get_app_additional_env_options(app, app_message) ⇒ Object



133
134
135
136
137
138
139
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 133

def get_app_additional_env_options(app, app_message)
  app_name = (app.is_a?(Hash) && app[:app].present?) ? app[:app].camelcase : app
  app_name = app_name.present? ? app_name : 'current application'
  message = "Please write additional ENV options for #{app_name} for #{app_message}"
  set :app_additional_env_options, CapistranoMulticonfigParallel.ask_confirm(message, nil)
  fetch_app_additional_env_options
end

#initialize_dataObject



51
52
53
54
55
56
57
58
59
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 51

def initialize_data
  @application = custom_command? ? nil : @top_level_tasks.first.split(':').reverse[1]
  @stage = custom_command? ? nil : @top_level_tasks.first.split(':').reverse[0]
  @stage = @stage.present? ? @stage : @default_stage
  @name, @args = @cap_app.parse_task_string(@top_level_tasks.second)
  @argv = @cap_app.handle_options.delete_if { |arg| arg == @stage || arg == @name || arg == @top_level_tasks.first }
  @argv = multi_fetch_argv(@argv)
  @original_argv = @argv.clone
end

#multi_apps?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 36

def multi_apps?
  @cap_app.multi_apps?
end

#process_jobsObject



81
82
83
84
85
86
87
88
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 81

def process_jobs
  return unless @jobs.present?
  if CapistranoMulticonfigParallel.execute_in_sequence
    @jobs.each { |job| CapistranoMulticonfigParallel::StandardDeploy.execute_standard_deploy(job) }
  else
    run_async_jobs
  end
end

#start(&block) ⇒ Object



44
45
46
47
48
49
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 44

def start(&block)
  check_before_starting
  initialize_data
  block.call if block_given?
  run
end

#tag_staging_exists?Boolean

check exists task from capistrano-gitflow

Returns:

  • (Boolean)


90
91
92
93
94
95
96
97
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 90

def tag_staging_exists? # check exists task from capistrano-gitflow
  rake1 = Rake::Task[CapistranoMulticonfigParallel::GITFLOW_TAG_STAGING_TASK]
  rake2 = Rake::Task[GITFLOW_CALCULATE_TAG_TASK]
  rake3 = Rake::Task[GITFLOW_VERIFY_UPTODATE_TASK]
  rake1.present? && check_giflow_tasks(rake2, rake3)
rescue
  return false
end

#verify_options_custom_command(options) ⇒ Object



61
62
63
64
65
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 61

def verify_options_custom_command(options)
  options[:action] = @argv['ACTION'].present? ? @argv['ACTION'] : 'deploy'
  @argv = @argv['ACTION'].present? ? @argv.except('ACTION') : @argv
  options
end

#wants_deploy_production?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 110

def wants_deploy_production?
  (!custom_command? && @stage == 'production') || (custom_command? && fetch_multi_stages.include?('production'))
end

#worker_environmentsObject



141
142
143
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 141

def worker_environments
   @jobs.map { |job| job['env'] }
end