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

#application ⇒ Object

Returns the value of attribute application.



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

def application
  @application
end

#args ⇒ Object

Returns the value of attribute args.



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

def args
  @args
end

#argv ⇒ Object

Returns the value of attribute argv.



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

def argv
  @argv
end

#condition ⇒ Object

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_stage ⇒ Object

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

#deps ⇒ Object

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_condition ⇒ Object

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

#jobs ⇒ Object

Returns the value of attribute jobs.



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

def jobs
  @jobs
end

#manager ⇒ Object

Returns the value of attribute manager.



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

def manager
  @manager
end

#name ⇒ Object

Returns the value of attribute name.



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

def name
  @name
end

#stage ⇒ Object

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

#check_before_starting ⇒ Object



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

def check_before_starting
  @condition = Celluloid::Condition.new
  @manager = CapistranoMulticonfigParallel::CelluloidManager.new(Actor.current)
end

#check_multi_stages(stages) ⇒ Object



101
102
103
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 101

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

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



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

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

#configuration ⇒ Object



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

def configuration
  CapistranoMulticonfigParallel.configuration
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_commands ⇒ Object



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



105
106
107
108
109
110
111
112
113
114
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 105

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_stages ⇒ Object



87
88
89
90
91
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 87

def fetch_multi_stages
  stages = @argv['STAGES'].blank? ? '' : @argv['STAGES']
  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



116
117
118
119
120
121
122
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 116

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

#is_able_to_tag_staging? ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 97

def is_able_to_tag_staging?
    using_git? &&  wants_deploy_production? && tag_staging_exists? 
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_jobs ⇒ Object



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

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
50
51
52
53
54
55
56
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 44

def start(&block)
  CapistranoMulticonfigParallel.configuration_valid?
  @default_stage = CapistranoMulticonfigParallel.configuration.development_stages.present? ? CapistranoMulticonfigParallel.configuration.development_stages.first : 'development'
  check_before_starting
  @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)
  block.call if block_given?
  run
end

#tag_staging_exists? ⇒ Boolean

check exists task from capistrano-gitflow

Returns:

  • (Boolean)


79
80
81
82
83
84
85
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 79

def tag_staging_exists? # check exists task from capistrano-gitflow
  begin
    Rake::Task[CapistranoMulticonfigParallel::GITFLOW_TAG_STAGING_TASK].present?
  rescue
    return false
  end
end

#wants_deploy_production? ⇒ Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/capistrano_multiconfig_parallel/helpers/base_manager.rb', line 93

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