Class: CapistranoMulticonfigParallel::MultiAppManager

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

Overview

class used to find application dependencies

Instance Attribute Summary

Attributes inherited from BaseManager

#application, #args, #argv, #condition, #default_stage, #deps, #job_registered_condition, #jobs, #manager, #name, #original_argv, #stage

Instance Method Summary collapse

Methods inherited from BaseManager

#can_start?, #can_tag_staging?, #check_giflow_tasks, #check_multi_stages, #collect_jobs, #configuration, #confirmation_applies_to_all_workers?, #custom_command?, #custom_commands, #deploy_app, #executes_deploy_stages?, #fetch_multi_stages, #get_app_additional_env_options, #initialize_data, #multi_apps?, #process_jobs, #start, #tag_staging_exists?, #verify_options_custom_command, #wants_deploy_production?, #worker_environments

Constructor Details

#initialize(cap_app, top_level_tasks, stages) ⇒ MultiAppManager

Returns a new instance of MultiAppManager.



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

def initialize(cap_app, top_level_tasks, stages)
  super(cap_app, top_level_tasks, stages)
  @dependency_tracker = CapistranoMulticonfigParallel::DependencyTracker.new(Actor.current)
end

Instance Method Details

#check_before_startingObject



14
15
16
17
# File 'lib/capistrano_multiconfig_parallel/helpers/multi_app_manager.rb', line 14

def check_before_starting
  verify_app_dependencies(@stages) if configuration.present? && configuration.track_dependencies.to_s.downcase == 'true'
  super
end


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

def menu_deploy_interactive(options)
  multi_collect_and_run_jobs(options) do |apps, new_options|
    deploy_multiple_apps(apps, new_options)
    deploy_app(new_options) if !custom_command? && new_options['app'].present?
  end
end

#multi_stage_deploy(options) ⇒ Object



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

def multi_stage_deploy(options)
  stages = fetch_multi_stages
  return if stages.blank?
  stages = check_multi_stages(stages)
  multi_collect_and_run_jobs(options) do |apps, new_options|
    apps.each do |app|
      stages.each do |stage|
        deploy_app(new_options.merge('app' => app, 'stage' => stage))
      end
    end if apps.present?
  end
end

#runObject



27
28
29
30
31
32
33
34
35
# File 'lib/capistrano_multiconfig_parallel/helpers/multi_app_manager.rb', line 27

def run
  options = {}
  if custom_command?
    run_custom_command(options)
  else
    menu_deploy_interactive(options)
  end
  process_jobs
end

#run_custom_command(options) ⇒ Object



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

def run_custom_command(options)
  return unless custom_command?
  CapistranoMulticonfigParallel.interactive_menu = true
  options = verify_options_custom_command(options)
  action_name = @name
  if action_name == custom_commands[:stages]
    multi_stage_deploy(options)
  else
    raise "Custom command #{@name} not available for multi apps"
  end
end

#verify_app_dependencies(stages) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
# File 'lib/capistrano_multiconfig_parallel/helpers/multi_app_manager.rb', line 19

def verify_app_dependencies(stages)
  applications = stages.map { |stage| stage.split(':').reverse[1] }
  wrong = configuration.application_dependencies.find do |hash|
    !applications.include?(hash[:app]) || (hash[:dependencies].present? && hash[:dependencies].find { |val| !applications.include?(val) })
  end
  raise ArgumentError, "invalid configuration for #{wrong.inspect}" if wrong.present?
end