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
18
# 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.configuration_valid?
  CapistranoMulticonfigParallel.verify_app_dependencies(@stages) if CapistranoMulticonfigParallel.configuration.track_dependencies
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

#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)


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

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

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



47
48
49
50
51
52
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 47

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

#custom_command?Boolean

Returns:

  • (Boolean)


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

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



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

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

#deploy_app(options = {}) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 69

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

#fetch_multi_stagesObject



63
64
65
66
67
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 63

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

#multi_apps?Boolean

Returns:

  • (Boolean)


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

def multi_apps?
  @cap_app.multi_apps?
end

#process_jobs(&block) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 54

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

#start(&block) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 37

def start(&block)
  @application = custom_command? ? nil : @top_level_tasks.first.split(':').reverse[1]
  @stage = custom_command? ? nil : @top_level_tasks.first.split(':').reverse[0]
  @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)
  block.call if block_given?
  run
end