capistrano_multiconfig_parallel 0.8.3 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b20d2ee84ec2ed3ed429a379cfed127acc0aeb88
4
- data.tar.gz: b18344f2beaadc2e8471ae5a8b974853e912e59b
3
+ metadata.gz: 3dface583820b0494ab0c4243c2daae6dc203a9b
4
+ data.tar.gz: fba2ef6001a82b06fcc43c7ba4094b2151577bef
5
5
  SHA512:
6
- metadata.gz: 609aba7897211c50b8c2877c677b1a94d24f10c8a829317d4a63ba47162603f139b3a848b1a9cdb806c830871ef35fae423df7bc391317973ca7cf0911c93dee
7
- data.tar.gz: c0c38bf78cf472833d5dc49f704627ce2c04dd9ac29788c1ff2eb65efa9d685dbb752db470ba82e38866d7376460a850bc0c805aa86247fc1bfbb2a62752c048
6
+ metadata.gz: 569dc97b2f9baff197a34c65514df8714e92c4ef6e908e7c2a545d9538f1453df9fb8d3c9459aac7bc67c70bbb500f2414dc81e89fd7650bba5cd281f461916d
7
+ data.tar.gz: b312a7d1503ed68d5d2a66cc0ec7a1f33f1aefdfcc85469e89c05754b3591939f5e612d40d7ec59c3defbd1ba4ab7cd50126225d71bfc3d2dbfa408351996149
@@ -183,7 +183,7 @@ module CapistranoMulticonfigParallel
183
183
  message = "Do you want to continue the deployment and execute #{task.upcase}"
184
184
  message += " for JOB #{worker.job_id}" if worker.present?
185
185
  message += '?'
186
- set :apps_symlink_confirmation, CapistranoMulticonfigParallel.ask_confirm(message, 'Y/N')
186
+ set :apps_symlink_confirmation, Celluloid::Actor[:terminal_server].show_confirmation(message, 'Y/N')
187
187
  until fetch(:apps_symlink_confirmation).present?
188
188
  sleep(0.1) # keep current thread alive
189
189
  end
@@ -54,10 +54,7 @@ module CapistranoMulticonfigParallel
54
54
  def publish_rake_event(data)
55
55
  @client.publish(rake_actor_id(data), data)
56
56
  end
57
-
58
- def publish_io_event(data)
59
- @client.publish("rake_io_#{@job_id}", 'approved' => 'yes', 'action' => 'stdin', 'job_id' => @job_id, 'result' => data)
60
- end
57
+
61
58
 
62
59
  def rake_actor_id(data)
63
60
  data['action'].present? && data['action'] == 'count' ? "rake_worker_#{@job_id}_count" : "rake_worker_#{@job_id}"
@@ -139,11 +136,18 @@ module CapistranoMulticonfigParallel
139
136
  update_machine_state(message['task']) # if message['action'] == 'invoke'
140
137
  debug("worker #{@job_id} state is #{@machine.state}") if debug_enabled?
141
138
  task_approval(message)
139
+ elsif message_is_for_stdout?(message)
140
+ result = Celluloid::Actor[:terminal_server].show_confirmation(message['question'],message['default'])
141
+ publish_rake_event(message.merge('action' => "stdin",'result' => result, "client_action" => "stdin"))
142
142
  else
143
143
  debug("worker #{@job_id} could not handle #{message}") if debug_enabled?
144
144
  end
145
145
  end
146
146
 
147
+ def message_is_for_stdout?(message)
148
+ message.present? && message.is_a?(Hash) && message['action'].present? && message['job_id'].present? && message['action'] == 'stdout'
149
+ end
150
+
147
151
  def message_is_about_a_task?(message)
148
152
  message.present? && message.is_a?(Hash) && message['action'].present? && message['job_id'].present? && message['task'].present?
149
153
  end
@@ -101,32 +101,9 @@ module CapistranoMulticonfigParallel
101
101
  def watch_handler(process)
102
102
  @process ||= process
103
103
  end
104
-
105
- def get_question_details(data)
106
- question = ''
107
- default = nil
108
- if data =~ /(.*)\?+\s*\:*\s*(\([^)]*\))*/m
109
- question = Regexp.last_match(1)
110
- default = Regexp.last_match(2)
111
- end
112
- question.present? ? [question, default] : nil
113
- end
114
-
115
- def printing_question?(data)
116
- get_question_details(data).present?
117
- end
118
-
119
- def user_prompt_needed?(data)
120
- return unless printing_question?(data)
121
- details = get_question_details(data)
122
- default = details.second.present? ? details.second : nil
123
- result = CapistranoMulticonfigParallel.ask_confirm(details.first, default)
124
- @actor.publish_io_event(result)
125
- end
126
104
 
127
105
  def io_callback(io, data)
128
106
  @worker_log.debug("#{io.upcase} ---- #{data}")
129
- # user_prompt_needed?(data)
130
107
  end
131
108
  end
132
109
  end
@@ -4,41 +4,49 @@ module CapistranoMulticonfigParallel
4
4
  include Celluloid
5
5
  include Celluloid::Logger
6
6
 
7
- attr_accessor :env, :client, :job_id, :action, :task, :task_approved, :successfull_subscription, :subscription_channel, :publisher_channel, :stdin_result
7
+ attr_accessor :env, :client, :job_id, :action, :task,
8
+ :task_approved, :successfull_subscription,
9
+ :subscription_channel, :publisher_channel, :stdin_result,
10
+ :questions_prompted, :nitialize_options
11
+
12
+
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
+
8
26
 
9
27
  def work(env, options = {})
10
28
  @options = options.stringify_keys
11
29
  @env = env
12
- default_settings
13
- custom_attributes
14
- initialize_subscription
15
- end
16
-
17
- def custom_attributes
18
- @publisher_channel = "worker_#{@job_id}"
19
- @action = @options['actor_id'].include?('_count') ? 'count' : 'invoke'
30
+ @action = @subscription_channel.include?('_count') ? 'count' : 'invoke'
20
31
  @task = @options['task']
32
+ wait_execution until @successfull_subscription == true && defined?(@client)
33
+ publish_to_worker(task_data)
21
34
  end
22
35
 
36
+
37
+
23
38
  def wait_execution(name = task_name, time = 0.1)
24
- # info "Before waiting #{name}"
39
+ # info "Before waiting #{name}"
25
40
  Actor.current.wait_for(name, time)
26
- # info "After waiting #{name}"
41
+ # info "After waiting #{name}"
27
42
  end
28
43
 
29
44
  def wait_for(name, time)
30
- # info "waiting for #{time} seconds on #{name}"
45
+ # info "waiting for #{time} seconds on #{name}"
31
46
  sleep time
32
- # info "done waiting on #{name} "
47
+ # info "done waiting on #{name} "
33
48
  end
34
49
 
35
- def default_settings
36
- @stdin_result = nil
37
- @job_id = @options['job_id']
38
- @subscription_channel = @options['actor_id']
39
- @task_approved = false
40
- @successfull_subscription = false
41
- end
42
50
 
43
51
  def initialize_subscription
44
52
  @client = CelluloidPubsub::Client.connect(actor: Actor.current, enable_debug: debug_enabled?) do |ws|
@@ -47,7 +55,7 @@ module CapistranoMulticonfigParallel
47
55
  end
48
56
 
49
57
  def debug_enabled?
50
- CapistranoMulticonfigParallel::CelluloidManager.debug_websocket?
58
+ CapistranoMulticonfigParallel::CelluloidManager.debug_websocket?
51
59
  end
52
60
 
53
61
  def task_name
@@ -62,25 +70,20 @@ module CapistranoMulticonfigParallel
62
70
  }
63
71
  end
64
72
 
65
- def publish_new_work(env, new_options = {})
66
- work(env, @options.merge(new_options))
67
- after_publishing_new_work
68
- end
69
-
70
- def after_publishing_new_work
71
- publish_to_worker(task_data)
72
- end
73
73
 
74
74
  def publish_to_worker(data)
75
75
  @client.publish(@publisher_channel, data)
76
76
  end
77
77
 
78
78
  def on_message(message)
79
- debug("Rake worker #{@job_id} received after parse #{message}") if debug_enabled?
79
+ debug("Rake worker #{@job_id} received after parse #{message}") #if debug_enabled?
80
80
  if @client.succesfull_subscription?(message)
81
- publish_subscription_successfull
82
- elsif message.present? && message['client_action'].blank?
81
+ debug("Rake worker #{@job_id} received parse #{message}") if debug_enabled?
82
+ @successfull_subscription = true
83
+ elsif message.present? && message['task'].present?
83
84
  task_approval(message)
85
+ elsif message.present? && message['action'].present? && message['action'] == 'stdin'
86
+ stdin_approval(message)
84
87
  else
85
88
  warn "unknown action: #{message.inspect}" if debug_enabled?
86
89
  end
@@ -91,14 +94,21 @@ module CapistranoMulticonfigParallel
91
94
  end
92
95
 
93
96
  def publish_subscription_successfull
94
- debug("Rake worker #{@job_id} received parse #{message}") if debug_enabled?
95
- publish_to_worker(task_data)
96
- @successfull_subscription = true
97
+
98
+ end
99
+
100
+ def wait_for_stdin_input
101
+ until @stdin_result.present?
102
+ wait_execution
103
+ end
104
+ output = @stdin_result.clone
105
+ Actor.current.stdin_result = nil
106
+ output
97
107
  end
98
108
 
99
109
  def stdin_approval(message)
100
- if @job_id.to_i == message['job_id'].to_i && message['approved'] == 'yes'
101
- @stdin_result = message
110
+ if @job_id.to_i == message['job_id'].to_i && message['result'].present? && message['action'] == 'stdin'
111
+ @stdin_result = message['result']
102
112
  else
103
113
  warn "unknown invocation #{message.inspect}" if debug_enabled?
104
114
  end
@@ -116,5 +126,41 @@ module CapistranoMulticonfigParallel
116
126
  debug("websocket connection closed: #{code.inspect}, #{reason.inspect}") if debug_enabled?
117
127
  terminate
118
128
  end
129
+
130
+ def get_question_details(data)
131
+ question = ''
132
+ default = nil
133
+ if data =~ /(.*)\?+\s*\:*\s*(\([^)]*\))*/m
134
+ question = Regexp.last_match(1)
135
+ default = Regexp.last_match(2)
136
+ end
137
+ question.present? ? [question, default] : nil
138
+ end
139
+
140
+ def printing_question?(data)
141
+ get_question_details(data).present?
142
+ end
143
+
144
+ def has_asked_question?(question)
145
+ @questions_prompted.include?(question)
146
+ end
147
+
148
+ def user_prompt_needed?(data)
149
+ return if !printing_question?(data) || has_asked_question?(data)
150
+
151
+ details = get_question_details(data)
152
+ default = details.second.present? ? details.second : nil
153
+ publish_to_worker({
154
+ action: "stdout",
155
+ question: details.first,
156
+ default: default.delete('()'),
157
+ job_id: @job_id
158
+ })
159
+ @questions_prompted << data
160
+
161
+
162
+ end
163
+
164
+
119
165
  end
120
166
  end
@@ -38,10 +38,17 @@ module CapistranoMulticonfigParallel
38
38
  terminate
39
39
  end
40
40
 
41
+
42
+ def show_confirmation(message, default)
43
+ exclusive do
44
+ CapistranoMulticonfigParallel.ask_confirm(message, default)
45
+ end
46
+ end
47
+
41
48
  def message_valid?(message)
42
49
  message[:type].present? && message[:type] == 'output' || message[:type] == 'event'
43
50
  end
44
-
51
+
45
52
  def show_terminal_screen(table)
46
53
  return unless table.rows.present?
47
54
  terminal_clear
@@ -16,29 +16,28 @@ module CapistranoMulticonfigParallel
16
16
  ENV['count_rake'].present? ? "rake_worker_#{job_id}_count" : "rake_worker_#{job_id}"
17
17
  end
18
18
 
19
- def stdin_result
20
- Celluloid::Actor[rake_actor_id].stdin_result
21
- end
19
+ def actor
20
+ CapistranoMulticonfigParallel::RakeWorker.supervise_as(rake_actor_id,
21
+ actor_id: rake_actor_id,
22
+ job_id: job_id) if Celluloid::Actor[rake_actor_id].blank?
23
+ Celluloid::Actor[rake_actor_id]
24
+ end
25
+
26
+ def run_the_actor(task, &block)
27
+ actor.work(ENV, task: task)
28
+ actor.wait_execution until actor.task_approved
29
+ return unless actor.task_approved
30
+ CapistranoMulticonfigParallel::InputStream.hook(actor)
31
+ CapistranoMulticonfigParallel::OutputStream.hook(actor)
32
+ block.call
33
+ CapistranoMulticonfigParallel::InputStream.unhook
34
+ CapistranoMulticonfigParallel::OutputStream.unhook
35
+ end
36
+
37
+
38
+
22
39
 
23
- def run_stdin_actor
24
- Celluloid::Actor[rake_actor_id].wait_execution('stdin') until stdin_result
25
- output = stdin_result.dup
26
- Celluloid::Actor[rake_actor_id].stdin_result = nil
27
- output
28
- end
29
40
 
30
- def run_the_actor(task)
31
- if Celluloid::Actor[rake_actor_id].blank?
32
- CapistranoMulticonfigParallel::RakeWorker.supervise_as rake_actor_id
33
- Celluloid::Actor[rake_actor_id].work(ENV, actor_id: rake_actor_id, job_id: job_id, task: task)
34
- else
35
- Celluloid::Actor[rake_actor_id].publish_new_work(ENV, task: task)
36
- end
37
- until Celluloid::Actor[rake_actor_id].task_approved
38
- Celluloid::Actor[rake_actor_id].wait_execution
39
- end
40
- yield Celluloid::Actor[rake_actor_id] if Celluloid::Actor[rake_actor_id].task_approved
41
- end
42
41
  end
43
42
  end
44
43
  end
@@ -0,0 +1,32 @@
1
+ module CapistranoMulticonfigParallel
2
+ class InputStream
3
+ def self.hook(actor)
4
+ $stdin = new($stdin, actor)
5
+ end
6
+
7
+ def self.unhook
8
+ $stdin.finish if $stdin.is_a? CapistranoMulticonfigParallel::InputStream
9
+ $stdin = STDIN
10
+ end
11
+
12
+ attr_accessor :real, :actor
13
+
14
+ def initialize(real_stdin, actor)
15
+ self.real = real_stdin
16
+ self.actor = actor
17
+ end
18
+
19
+ def gets(*args)
20
+ @actor.wait_for_stdin_input
21
+ end
22
+
23
+ def finish
24
+
25
+ end
26
+
27
+ def method_missing(name, *args, &block)
28
+ @real.send name, *args, &block
29
+ end
30
+ end
31
+ end
32
+
@@ -0,0 +1,38 @@
1
+ module CapistranoMulticonfigParallel
2
+ class OutputStream
3
+ def self.hook(actor)
4
+ $stdout = new($stdout, actor)
5
+ end
6
+
7
+ def self.unhook
8
+ $stdout.finish if $stdout.is_a? CapistranoMulticonfigParallel::OutputStream
9
+ $stdout = STDOUT
10
+ end
11
+
12
+ attr_accessor :real, :actor, :strings
13
+
14
+ def initialize(real_stdout, actor)
15
+ self.real= real_stdout
16
+ self.actor = actor
17
+ self.strings = []
18
+ end
19
+
20
+ def write(*args)
21
+ @real.write(*args)
22
+ @real.flush
23
+ @actor.user_prompt_needed?(args.join(' '))
24
+ end
25
+
26
+
27
+
28
+
29
+ def finish
30
+
31
+ end
32
+
33
+ def method_missing(name, *args, &block)
34
+ @real.send name, *args, &block
35
+ end
36
+ end
37
+ end
38
+
@@ -1,4 +1,6 @@
1
1
  require_relative './extension_helper'
2
+ require_relative './input_stream'
3
+ require_relative './output_stream'
2
4
  Rake::Task.class_eval do
3
5
  alias_method :original_execute, :execute
4
6
 
@@ -7,8 +7,8 @@ module CapistranoMulticonfigParallel
7
7
  # module used for generating the version
8
8
  module VERSION
9
9
  MAJOR = 0
10
- MINOR = 8
11
- TINY = 3
10
+ MINOR = 9
11
+ TINY = 0
12
12
  PRE = nil
13
13
 
14
14
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano_multiconfig_parallel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bogdanRada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-10 00:00:00.000000000 Z
11
+ date: 2015-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid-pmap
@@ -647,6 +647,8 @@ files:
647
647
  - lib/capistrano_multiconfig_parallel/cli.rb
648
648
  - lib/capistrano_multiconfig_parallel/configuration.rb
649
649
  - lib/capistrano_multiconfig_parallel/extensions/extension_helper.rb
650
+ - lib/capistrano_multiconfig_parallel/extensions/input_stream.rb
651
+ - lib/capistrano_multiconfig_parallel/extensions/output_stream.rb
650
652
  - lib/capistrano_multiconfig_parallel/extensions/rake.rb
651
653
  - lib/capistrano_multiconfig_parallel/helpers/base_manager.rb
652
654
  - lib/capistrano_multiconfig_parallel/helpers/multi_app_manager.rb