capistrano_multiconfig_parallel 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 867ce8da69cdf6500d2ee56333c109bc8d0dcf8a
4
- data.tar.gz: 14485e413c78e550ca6ce3d68172d247360249be
3
+ metadata.gz: 2bdac07ad222d4fcad77e8a8ec5f18898262f834
4
+ data.tar.gz: 212281163ee493733d40eb1af17ecc2a5dfd7c9c
5
5
  SHA512:
6
- metadata.gz: db431edc0e89fff08132da6b0cf85b39b75260e71a39e5180bcb3d8d190ab2b63913a2c7ac5beb359f9f9bc5926b4cd371ba0a1153e698a37c305b5e295a12bd
7
- data.tar.gz: 61657bacfd339847406ffc24dfc0064805567be1f447db96541e138239aba3d26cc06e62a1ae4e3222f27422cadcecfa12feddad4c25f2e00d9d84d56251ed39
6
+ metadata.gz: e7454e4f6f02a655932e940e50cadc77b6c19d7a551257b2d57d11219589635fec8b694d06b498725868ab7135dbce26f980284c44b9b2b6500ec65caf16118f
7
+ data.tar.gz: ab3f5c6f1c059582d90994e5c2150a9ab551da7ce4e9f840fb685ba2e3782245d47bcb13b23cd8da786e4d77d07ae15fb9ed5a40c05935f1fd6b9385230f872c
@@ -25,11 +25,12 @@ module CapistranoMulticonfigParallel
25
25
  attr_accessor :job, :manager, :job_id, :app_name, :env_name, :action_name, :env_options, :machine, :client, :task_argv, :execute_deploy, :executed_dry_run,
26
26
  :rake_tasks, :current_task_number, # tracking tasks
27
27
  :successfull_subscription, :subscription_channel, :publisher_channel, # for subscriptions and publishing events
28
- :job_termination_condition, :worker_state, :executing_dry_run
28
+ :job_termination_condition, :worker_state, :executing_dry_run, :job_argv
29
29
 
30
30
  def work(job, manager)
31
31
  @job = job
32
32
  @worker_state = 'started'
33
+ @executing_dry_run = nil
33
34
  @manager = manager
34
35
  @job_confirmation_conditions = []
35
36
  process_job(job) if job.present?
@@ -74,8 +75,7 @@ module CapistranoMulticonfigParallel
74
75
  if @action_name != 'deploy:rollback' && CapistranoMulticonfigParallel.show_task_progress
75
76
  @executed_dry_run = true
76
77
  @rake_tasks = []
77
- @executing_dry_run = true
78
- setup_task_arguments( '--dry-run','count_rake=true' )
78
+ setup_task_arguments(dry_run_command,'count_rake=true' )
79
79
  @child_process = CapistranoMulticonfigParallel::ChildProcess.new
80
80
  Actor.current.link @child_process
81
81
  debug("worker #{@job_id} executes: #{generate_command}") if debug_enabled?
@@ -106,7 +106,6 @@ module CapistranoMulticonfigParallel
106
106
  setup_task_arguments
107
107
  debug("worker #{@job_id} executes: #{generate_command}") if debug_enabled?
108
108
  @child_process.async.work(generate_command, actor: Actor.current, silent: true)
109
- @executing_dry_run = false
110
109
  @manager.wait_task_confirmations_worker(Actor.current)
111
110
  end
112
111
 
@@ -130,6 +129,8 @@ module CapistranoMulticonfigParallel
130
129
  end
131
130
 
132
131
  def handle_subscription(message)
132
+ @executing_dry_run = message['action'] == 'count' ? true : false
133
+ @manager.jobs[@job_id]['job_argv'] = @job_argv
133
134
  if message_is_about_a_task?(message)
134
135
  check_gitflow
135
136
  save_tasks_to_be_executed(message)
@@ -187,6 +188,14 @@ module CapistranoMulticonfigParallel
187
188
  @task_argv
188
189
  end
189
190
 
191
+ def dry_run_command
192
+ '--dry-run'
193
+ end
194
+
195
+ def dry_running?
196
+ @task_argv.include?(dry_run_command) == true
197
+ end
198
+
190
199
  def worker_stage
191
200
  @app_name.present? ? "#{@app_name}:#{@env_name}" : "#{@env_name}"
192
201
  end
@@ -205,7 +214,7 @@ module CapistranoMulticonfigParallel
205
214
  args.each do |arg|
206
215
  array_options << arg
207
216
  end
208
- @manager.jobs[@job_id]['job_argv'] = array_options.clone
217
+ @job_argv= array_options.clone
209
218
  array_options.unshift("#{worker_action}")
210
219
  array_options.unshift("#{worker_stage}")
211
220
  setup_command_line(*array_options)
@@ -11,29 +11,24 @@ module CapistranoMulticonfigParallel
11
11
 
12
12
 
13
13
 
14
- def initialize(options={})
15
- @initialize_options = options.stringify_keys
16
- @questions_prompted ||=[]
17
- @stdin_result = nil
18
- @job_id = @initialize_options['job_id']
19
- @subscription_channel = @initialize_options['actor_id']
20
- @publisher_channel = "worker_#{@job_id}"
21
- @task_approved = false
22
- @successfull_subscription = false
23
- initialize_subscription
24
- end
25
-
26
-
27
- def work(env, options = {})
14
+ def work(env, options = {})
28
15
  @options = options.stringify_keys
29
16
  @env = env
30
- @action = @subscription_channel.include?('_count') ? 'count' : 'invoke'
17
+ default_settings
18
+ custom_attributes
19
+ initialize_subscription
20
+ end
21
+
22
+ def custom_attributes
23
+ @publisher_channel = "worker_#{@job_id}"
24
+ @action = @options['actor_id'].include?('_count') ? 'count' : 'invoke'
31
25
  @task = @options['task']
32
- wait_execution until @successfull_subscription == true && defined?(@client)
33
- publish_to_worker(task_data)
34
26
  end
35
27
 
36
-
28
+ def publish_new_work(env, new_options = {})
29
+ work(env, @options.merge(new_options))
30
+ publish_to_worker(task_data)
31
+ end
37
32
 
38
33
  def wait_execution(name = task_name, time = 0.1)
39
34
  # info "Before waiting #{name}"
@@ -47,6 +42,13 @@ module CapistranoMulticonfigParallel
47
42
  # info "done waiting on #{name} "
48
43
  end
49
44
 
45
+ def default_settings
46
+ @stdin_result = nil
47
+ @job_id = @options['job_id']
48
+ @subscription_channel = @options['actor_id']
49
+ @task_approved = false
50
+ @successfull_subscription = false
51
+ end
50
52
 
51
53
  def initialize_subscription
52
54
  @client = CelluloidPubsub::Client.connect(actor: Actor.current, enable_debug: debug_enabled?) do |ws|
@@ -80,6 +82,7 @@ module CapistranoMulticonfigParallel
80
82
  if @client.succesfull_subscription?(message)
81
83
  debug("Rake worker #{@job_id} received parse #{message}") if debug_enabled?
82
84
  @successfull_subscription = true
85
+ publish_to_worker(task_data)
83
86
  elsif message.present? && message['task'].present?
84
87
  task_approval(message)
85
88
  elsif message.present? && message['action'].present? && message['action'] == 'stdin'
@@ -112,8 +112,13 @@ module CapistranoMulticonfigParallel
112
112
  { value: "#{details['state']}" }
113
113
  ]
114
114
  if CapistranoMulticonfigParallel.show_task_progress
115
- row << { value: worker.rake_tasks.size }
116
- row << { value: worker_progress(worker) }
115
+ if worker.alive?
116
+ row << { value: worker.rake_tasks.size }
117
+ row << { value: worker_progress(details, worker) }
118
+ else
119
+ row << { value: 0 }
120
+ row << { value: worker_state(worker) }
121
+ end
117
122
  end
118
123
  table.add_row(row)
119
124
  table.add_separator if @manager.jobs.keys.last.to_i != job_id.to_i
@@ -123,22 +128,21 @@ module CapistranoMulticonfigParallel
123
128
  system('cls') || system('clear') || puts("\e[H\e[2J")
124
129
  end
125
130
 
126
- def worker_progress(worker)
127
- return worker_state(worker) unless worker.alive?
128
- tasks = worker.rake_tasks
129
- current_task = worker.machine.state
130
- total_tasks = tasks.size
131
- task_index = tasks.index(current_task)
131
+ def worker_dry_running?(worker)
132
+ worker.alive? && worker.dry_running?
133
+ end
134
+
135
+ def worker_progress(details, worker)
136
+ return worker_state(worker) unless worker.alive?
137
+ return if worker.executing_dry_run.nil?
138
+ tasks = worker.alive? ? worker.rake_tasks : []
139
+ current_task = worker_state(worker)
140
+ total_tasks = worker_dry_running?(worker) ? nil : tasks.size
141
+ task_index = worker_dry_running?(worker) ? 0 : tasks.index(current_task).to_i + 1
132
142
  stringio = StringIO.new
133
- if worker.executing_dry_run == false
134
- #progress = ProgressBar::Base.new(:title => "Tasks", :output => stringio, :format => '%a %B %p%% %t', :starting_at => task_index.to_i, :total => total_tasks, :length => 40)
135
- progress = ProgressBar.create(:format => '%a |%b %i| %p%% Completed', :output => stringio, :starting_at => task_index, :total => total_tasks, :length => 40 )
136
- progress.refresh
137
- else
138
- progress = ProgressBar.create(:format => '%a |%b %i| %p%% Completed', :output => stringio, :length => 40, :total => nil, :unknown_progress_animation_steps => ['==>', '>==', '=>='])
139
- progress.increment
140
- progress.refresh
141
- end
143
+ progress_bar = ProgressBar.create(:output => stringio, :starting_at => task_index, :total => total_tasks, :length => 40, title: "JOB #{details['job_id']}: #{task_index.to_s} of #{total_tasks}")
144
+ progress_bar.refresh
145
+ progress_bar.stop
142
146
  stringio.rewind
143
147
  result = stringio.read
144
148
  result = result.gsub("\r\n", '')
@@ -4,43 +4,65 @@ require_relative './input_stream'
4
4
  require_relative './output_stream'
5
5
  module CapistranoMulticonfigParallel
6
6
  class ExtensionHelper
7
- class << self
8
- def inside_job?
9
- job_id.present?
10
- end
11
-
12
- def job_id
13
- ENV[CapistranoMulticonfigParallel::ENV_KEY_JOB_ID]
14
- end
15
-
16
-
17
- def rake_actor_id
18
- ENV['count_rake'].present? ? "rake_worker_#{job_id}_count" : "rake_worker_#{job_id}"
19
- end
20
-
21
- def actor
22
- CapistranoMulticonfigParallel::RakeWorker.supervise_as(rake_actor_id,
23
- actor_id: rake_actor_id,
24
- job_id: job_id) if Celluloid::Actor[rake_actor_id].blank?
25
- Celluloid::Actor[rake_actor_id]
26
- end
27
-
28
- def run_the_actor(task, &block)
29
- actor.work(ENV, task: task)
7
+
8
+ attr_accessor :task, :env
9
+ def initialize(env, task)
10
+ @env = env
11
+ @task = task
12
+ end
13
+
14
+ def work(&block)
15
+ if job_id.present?
16
+ actor_start_working
30
17
  actor.wait_execution until actor.task_approved
31
- return unless actor.task_approved
32
- stringio = StringIO.new
33
- CapistranoMulticonfigParallel::OutputStream.hook(stringio)
34
- CapistranoMulticonfigParallel::InputStream.hook(actor, stringio)
18
+ return unless actor.task_approved
19
+ actor_execute_block(&block)
20
+ else
35
21
  block.call
36
- CapistranoMulticonfigParallel::InputStream.unhook
37
- CapistranoMulticonfigParallel::OutputStream.unhook
38
22
  end
39
-
40
-
23
+ end
41
24
 
42
25
 
26
+
27
+ private
28
+
29
+
30
+ def actor_execute_block(&block)
31
+ stringio = StringIO.new
32
+ CapistranoMulticonfigParallel::OutputStream.hook(stringio)
33
+ CapistranoMulticonfigParallel::InputStream.hook(actor, stringio)
34
+ block.call
35
+ CapistranoMulticonfigParallel::InputStream.unhook
36
+ CapistranoMulticonfigParallel::OutputStream.unhook
37
+ end
38
+
39
+ def actor_start_working
40
+ if actor.blank?
41
+ CapistranoMulticonfigParallel::RakeWorker.supervise_as rake_actor_id
42
+ actor.work(@env, actor_id: rake_actor_id, job_id: job_id, task: @task)
43
+ else
44
+ actor.publish_new_work(@env, task: @task)
45
+ end
46
+ end
47
+
48
+ def supervise_actor
49
+ CapistranoMulticonfigParallel::RakeWorker.supervise_as(rake_actor_id,
50
+ actor_id: rake_actor_id,
51
+ job_id: job_id) if actor.blank?
52
+ end
53
+
54
+ def actor
55
+ Celluloid::Actor[rake_actor_id]
56
+ end
57
+
58
+ def job_id
59
+ @env[CapistranoMulticonfigParallel::ENV_KEY_JOB_ID]
60
+ end
61
+
43
62
 
63
+ def rake_actor_id
64
+ @env['count_rake'].present? ? "rake_worker_#{job_id}_count" : "rake_worker_#{job_id}"
44
65
  end
66
+
45
67
  end
46
68
  end
@@ -3,11 +3,8 @@ Rake::Task.class_eval do
3
3
  alias_method :original_execute, :execute
4
4
 
5
5
  def execute(*args)
6
- if CapistranoMulticonfigParallel::ExtensionHelper.inside_job?
7
- CapistranoMulticonfigParallel::ExtensionHelper.run_the_actor(self) do
8
- original_execute(*args)
9
- end
10
- else
6
+ rake = CapistranoMulticonfigParallel::ExtensionHelper.new(ENV, self)
7
+ rake.work do
11
8
  original_execute(*args)
12
9
  end
13
10
  end
@@ -7,7 +7,7 @@ module CapistranoMulticonfigParallel
7
7
  # module used for generating the version
8
8
  module VERSION
9
9
  MAJOR = 0
10
- MINOR = 10
10
+ MINOR = 11
11
11
  TINY = 0
12
12
  PRE = nil
13
13
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano_multiconfig_parallel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bogdanRada