capistrano_multiconfig_parallel 1.7.2 → 2.0.0.beta1

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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -2
  3. data/README.md +38 -36
  4. data/V1_README.md +351 -0
  5. data/capistrano_multiconfig_parallel.gemspec +5 -8
  6. data/lib/capistrano_multiconfig_parallel/all.rb +3 -7
  7. data/lib/capistrano_multiconfig_parallel/application.rb +10 -5
  8. data/lib/capistrano_multiconfig_parallel/base.rb +11 -11
  9. data/lib/capistrano_multiconfig_parallel/celluloid/celluloid_manager.rb +3 -2
  10. data/lib/capistrano_multiconfig_parallel/celluloid/celluloid_worker.rb +32 -20
  11. data/lib/capistrano_multiconfig_parallel/celluloid/child_process.rb +3 -0
  12. data/lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb +21 -14
  13. data/lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb +4 -3
  14. data/lib/capistrano_multiconfig_parallel/classes/cursor.rb +6 -2
  15. data/lib/capistrano_multiconfig_parallel/classes/dependency_tracker.rb +1 -1
  16. data/lib/capistrano_multiconfig_parallel/classes/job.rb +38 -13
  17. data/lib/capistrano_multiconfig_parallel/classes/job_command.rb +154 -15
  18. data/lib/capistrano_multiconfig_parallel/cli.rb +10 -26
  19. data/lib/capistrano_multiconfig_parallel/configuration/default.yml +1 -1
  20. data/lib/capistrano_multiconfig_parallel/helpers/application_helper.rb +26 -2
  21. data/lib/capistrano_multiconfig_parallel/helpers/capistrano_helper.rb +1 -1
  22. data/lib/capistrano_multiconfig_parallel/helpers/configuration.rb +3 -3
  23. data/lib/capistrano_multiconfig_parallel/helpers/gem_helper.rb +2 -1
  24. data/lib/capistrano_multiconfig_parallel/helpers/internal_helper.rb +18 -2
  25. data/lib/capistrano_multiconfig_parallel/version.rb +5 -4
  26. metadata +20 -60
  27. data/lib/capistrano_multiconfig_parallel/celluloid/rake_worker.rb +0 -132
  28. data/lib/capistrano_multiconfig_parallel/classes/input_stream.rb +0 -34
  29. data/lib/capistrano_multiconfig_parallel/classes/output_stream.rb +0 -33
  30. data/lib/capistrano_multiconfig_parallel/classes/rake_task_hooks.rb +0 -88
  31. data/lib/capistrano_multiconfig_parallel/initializers/capistrano2.rb +0 -37
  32. data/lib/capistrano_multiconfig_parallel/initializers/rake.rb +0 -11
  33. data/lib/capistrano_multiconfig_parallel/initializers/websocket.rb +0 -19
@@ -8,39 +8,23 @@ module CapistranoMulticonfigParallel
8
8
  # method used to start
9
9
  def start
10
10
  before_start
11
- arguments = multi_fetch_argv(original_args)
12
11
  configuration_valid?
13
- execute_start(arguments[CapistranoMulticonfigParallel::ENV_KEY_JOB_ID])
12
+ run_the_application
14
13
  end
15
14
 
16
- def execute_start(job_id)
17
- if job_id.blank?
18
- run_the_application
19
- else
20
- ARGV.reject! { |arg| arg_is_in_default_config?(arg) }
21
- log_to_file("worker #{job_id} runs with ARGV #{ARGV.inspect}", job_id: job_id)
22
- run_capistrano
23
- end
24
- end
25
-
26
- def run_capistrano
27
- if capistrano_version_2?
28
- require 'capistrano/cli'
29
- Capistrano::CLI.execute
30
- else
31
- require 'capistrano/all'
32
- Capistrano::Application.new.run
33
- end
34
- end
35
-
36
- def before_start
15
+ def before_start(argv = ARGV)
37
16
  check_terminal_tty
38
- CapistranoMulticonfigParallel.original_args = ARGV.dup
17
+ CapistranoMulticonfigParallel.original_args = argv.dup
39
18
  end
40
19
 
41
20
  def run_the_application
42
- execute_with_rescue('stderr') do
43
- CapistranoMulticonfigParallel::Application.new.start
21
+ begin
22
+ application = CapistranoMulticonfigParallel::Application.new
23
+ execute_with_rescue('stderr') do
24
+ application.start
25
+ end
26
+ ensure
27
+ application.jobs_restore_application_state
44
28
  end
45
29
  end
46
30
  end
@@ -17,7 +17,7 @@ default_config:
17
17
  type: 'boolean'
18
18
  description: >-
19
19
  Enables debugging of websocket communication between the workers
20
- default: 'false'
20
+ default: 'true'
21
21
  required: false
22
22
 
23
23
  - name: 'websocket_server.adapter'
@@ -17,13 +17,37 @@ module CapistranoMulticonfigParallel
17
17
  delegate :logger,
18
18
  :configuration,
19
19
  :configuration_valid?,
20
- :capistrano_version_2?,
21
- :capistrano_version,
22
20
  :original_args,
23
21
  to: :CapistranoMulticonfigParallel
24
22
 
23
+
25
24
  module_function
26
25
 
26
+ def truncate(string, truncate_at, options = {})
27
+ return string.dup unless string.length > truncate_at
28
+
29
+ options[:omission] ||= '...'
30
+ length_with_room_for_omission = truncate_at - options[:omission].length
31
+ stop = if options[:separator]
32
+ string.rindex(options[:separator], length_with_room_for_omission) || length_with_room_for_omission
33
+ else
34
+ length_with_room_for_omission
35
+ end
36
+
37
+ "#{string[0...stop]}#{options[:omission]}"
38
+ end
39
+
40
+ # Method that is used to parse a string as JSON , if it fails will return nil
41
+ # @see JSON#parse
42
+ # @param [string] res The string that will be parsed as JSON
43
+ # @return [Hash, nil] Returns Hash object if the json parse succeeds or nil otherwise
44
+ def parse_json(res)
45
+ return if res.blank?
46
+ JSON.parse(res)
47
+ rescue JSON::ParserError
48
+ nil
49
+ end
50
+
27
51
  def msg_for_stdin?(message)
28
52
  message['action'] == 'stdin'
29
53
  end
@@ -8,7 +8,7 @@ module CapistranoMulticonfigParallel
8
8
  end
9
9
 
10
10
  def env_prefix(key, version = false)
11
- key != CapistranoMulticonfigParallel::ENV_KEY_JOB_ID && version == true ? '-S' : ''
11
+ key != CapistranoMulticonfigParallel.env_job_key_id && version == true ? '-S' : ''
12
12
  end
13
13
 
14
14
  def env_key_format(key, version = false)
@@ -38,13 +38,13 @@ module CapistranoMulticonfigParallel
38
38
 
39
39
  def read_config_file
40
40
  return if CapistranoMulticonfigParallel.original_args.present? && CapistranoMulticonfigParallel.original_args.include?('--help')
41
- user = Etc.getlogin
41
+ user = Etc.getlogin
42
42
  config_file_path = File.join(Dir.home(user), "multi_cap.yml")
43
43
  if File.exists?(config_file_path)
44
- @fetched_config.config_dir = File.dirname(config_file_path)
44
+ @fetched_config.config_dir = File.dirname(config_file_path)
45
45
  else
46
46
  @fetched_config.config_dir = @fetched_config.config_dir.present? ? File.expand_path(@fetched_config.config_dir) : try_detect_file('multi_cap.yml')
47
- config_file_path = @fetched_config.config_dir.present? ? File.join(@fetched_config.config_dir, 'multi_cap.yml') : nil
47
+ config_file_path = @fetched_config.config_dir.present? ? File.join(@fetched_config.config_dir, 'multi_cap.yml') : nil
48
48
  end
49
49
  config_file = File.expand_path(config_file_path || File.join(detect_root.to_s, 'config', 'multi_cap.yml'))
50
50
  @fetched_config.log_dir = config_file_path.present? ? File.dirname(config_file) : File.dirname(File.dirname(config_file))
@@ -1,7 +1,7 @@
1
1
  module CapistranoMulticonfigParallel
2
2
  # helper used to determine gem versions
3
3
  module GemHelper
4
- module_function
4
+ module_function
5
5
 
6
6
  def find_loaded_gem(name, property = nil)
7
7
  gem_spec = Gem.loaded_specs.values.find { |repo| repo.name == name }
@@ -35,5 +35,6 @@ module CapistranoMulticonfigParallel
35
35
  version = get_parsed_version(version)
36
36
  get_parsed_version(gem_version).send(options.fetch('operator', '<='), version)
37
37
  end
38
+
38
39
  end
39
40
  end
@@ -1,7 +1,23 @@
1
1
  module CapistranoMulticonfigParallel
2
2
  # internal helpers for logging mostly
3
3
  module InternalHelper
4
- module_function
4
+ module_function
5
+
6
+ def get_current_gem_name
7
+ searcher = if Gem::Specification.respond_to? :find
8
+ # ruby 2.0
9
+ Gem::Specification
10
+ elsif Gem.respond_to? :searcher
11
+ # ruby 1.8/1.9
12
+ Gem.searcher.init_gemspecs
13
+ end
14
+ spec = unless searcher.nil?
15
+ searcher.find do |spec|
16
+ File.fnmatch(File.join(spec.full_gem_path,'*'), __FILE__)
17
+ end
18
+ end
19
+ spec.name if spec.present?
20
+ end
5
21
 
6
22
  def get_current_gem_name
7
23
  searcher = if Gem::Specification.respond_to? :find
@@ -46,7 +62,7 @@ module CapistranoMulticonfigParallel
46
62
  end
47
63
 
48
64
  def default_config_keys
49
- default_internal_config.map { |array| array[0].to_s }.concat([CapistranoMulticonfigParallel::ENV_KEY_JOB_ID])
65
+ default_internal_config.map { |array| array[0].to_s }.concat([CapistranoMulticonfigParallel.env_job_key_id, 'capistrano_version'])
50
66
  end
51
67
 
52
68
  def arg_is_in_default_config?(arg)
@@ -6,10 +6,11 @@ module CapistranoMulticonfigParallel
6
6
 
7
7
  # module used for generating the version
8
8
  module VERSION
9
- MAJOR = 1
10
- MINOR = 7
11
- TINY = 2
12
- PRE = nil
9
+
10
+ MAJOR = 2
11
+ MINOR = 0
12
+ TINY = 0
13
+ PRE = 'beta1'
13
14
 
14
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
15
16
  end
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: 1.7.2
4
+ version: 2.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - bogdanRada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-08 00:00:00.000000000 Z
11
+ date: 2016-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid
@@ -17,9 +17,6 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.16'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 0.16.0
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +24,6 @@ dependencies:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0.16'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 0.16.0
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: celluloid-pmap
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -59,7 +53,7 @@ dependencies:
59
53
  version: '0.8'
60
54
  - - ">="
61
55
  - !ruby/object:Gem::Version
62
- version: 0.8.2
56
+ version: 0.8.3
63
57
  type: :runtime
64
58
  prerelease: false
65
59
  version_requirements: !ruby/object:Gem::Requirement
@@ -69,27 +63,7 @@ dependencies:
69
63
  version: '0.8'
70
64
  - - ">="
71
65
  - !ruby/object:Gem::Version
72
- version: 0.8.2
73
- - !ruby/object:Gem::Dependency
74
- name: celluloid-websocket-client
75
- requirement: !ruby/object:Gem::Requirement
76
- requirements:
77
- - - "~>"
78
- - !ruby/object:Gem::Version
79
- version: '0.0'
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: 0.0.1
83
- type: :runtime
84
- prerelease: false
85
- version_requirements: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '0.0'
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- version: 0.0.1
66
+ version: 0.8.3
93
67
  - !ruby/object:Gem::Dependency
94
68
  name: composable_state_machine
95
69
  requirement: !ruby/object:Gem::Requirement
@@ -190,34 +164,20 @@ dependencies:
190
164
  - - ">="
191
165
  - !ruby/object:Gem::Version
192
166
  version: 3.0.1
193
- - !ruby/object:Gem::Dependency
194
- name: capistrano
195
- requirement: !ruby/object:Gem::Requirement
196
- requirements:
197
- - - ">="
198
- - !ruby/object:Gem::Version
199
- version: '2.0'
200
- type: :runtime
201
- prerelease: false
202
- version_requirements: !ruby/object:Gem::Requirement
203
- requirements:
204
- - - ">="
205
- - !ruby/object:Gem::Version
206
- version: '2.0'
207
167
  - !ruby/object:Gem::Dependency
208
168
  name: activesupport
209
169
  requirement: !ruby/object:Gem::Requirement
210
170
  requirements:
211
171
  - - ">="
212
172
  - !ruby/object:Gem::Version
213
- version: '4.0'
173
+ version: '5.0'
214
174
  type: :runtime
215
175
  prerelease: false
216
176
  version_requirements: !ruby/object:Gem::Requirement
217
177
  requirements:
218
178
  - - ">="
219
179
  - !ruby/object:Gem::Version
220
- version: '4.0'
180
+ version: '5.0'
221
181
  - !ruby/object:Gem::Dependency
222
182
  name: configliere
223
183
  requirement: !ruby/object:Gem::Requirement
@@ -279,19 +239,25 @@ dependencies:
279
239
  - !ruby/object:Gem::Version
280
240
  version: '0.1'
281
241
  - !ruby/object:Gem::Dependency
282
- name: rack
242
+ name: capistrano_sentinel
283
243
  requirement: !ruby/object:Gem::Requirement
284
244
  requirements:
285
245
  - - ">="
286
246
  - !ruby/object:Gem::Version
287
- version: '1.6'
247
+ version: '0.0'
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: 0.0.14
288
251
  type: :runtime
289
252
  prerelease: false
290
253
  version_requirements: !ruby/object:Gem::Requirement
291
254
  requirements:
292
255
  - - ">="
293
256
  - !ruby/object:Gem::Version
294
- version: '1.6'
257
+ version: '0.0'
258
+ - - ">="
259
+ - !ruby/object:Gem::Version
260
+ version: 0.0.14
295
261
  - !ruby/object:Gem::Dependency
296
262
  name: rake
297
263
  requirement: !ruby/object:Gem::Requirement
@@ -299,7 +265,7 @@ dependencies:
299
265
  - - ">="
300
266
  - !ruby/object:Gem::Version
301
267
  version: '10.4'
302
- type: :runtime
268
+ type: :development
303
269
  prerelease: false
304
270
  version_requirements: !ruby/object:Gem::Requirement
305
271
  requirements:
@@ -508,6 +474,7 @@ files:
508
474
  - LICENSE
509
475
  - README.md
510
476
  - Rakefile
477
+ - V1_README.md
511
478
  - bin/multi_cap
512
479
  - capistrano_multiconfig_parallel.gemspec
513
480
  - img/interactive_menu-min.png
@@ -520,18 +487,14 @@ files:
520
487
  - lib/capistrano_multiconfig_parallel/celluloid/celluloid_manager.rb
521
488
  - lib/capistrano_multiconfig_parallel/celluloid/celluloid_worker.rb
522
489
  - lib/capistrano_multiconfig_parallel/celluloid/child_process.rb
523
- - lib/capistrano_multiconfig_parallel/celluloid/rake_worker.rb
524
490
  - lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
525
491
  - lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb
526
492
  - lib/capistrano_multiconfig_parallel/celluloid/web_server.rb
527
493
  - lib/capistrano_multiconfig_parallel/classes/cursor.rb
528
494
  - lib/capistrano_multiconfig_parallel/classes/dependency_tracker.rb
529
- - lib/capistrano_multiconfig_parallel/classes/input_stream.rb
530
495
  - lib/capistrano_multiconfig_parallel/classes/interactive_menu.rb
531
496
  - lib/capistrano_multiconfig_parallel/classes/job.rb
532
497
  - lib/capistrano_multiconfig_parallel/classes/job_command.rb
533
- - lib/capistrano_multiconfig_parallel/classes/output_stream.rb
534
- - lib/capistrano_multiconfig_parallel/classes/rake_task_hooks.rb
535
498
  - lib/capistrano_multiconfig_parallel/cli.rb
536
499
  - lib/capistrano_multiconfig_parallel/configuration/default.yml
537
500
  - lib/capistrano_multiconfig_parallel/helpers/application_helper.rb
@@ -543,9 +506,6 @@ files:
543
506
  - lib/capistrano_multiconfig_parallel/helpers/internal_helper.rb
544
507
  - lib/capistrano_multiconfig_parallel/helpers/parse_helper.rb
545
508
  - lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb
546
- - lib/capistrano_multiconfig_parallel/initializers/capistrano2.rb
547
- - lib/capistrano_multiconfig_parallel/initializers/rake.rb
548
- - lib/capistrano_multiconfig_parallel/initializers/websocket.rb
549
509
  - lib/capistrano_multiconfig_parallel/version.rb
550
510
  homepage: http://github.com/bogdanRada/capistrano_multiconfig_parallel/
551
511
  licenses:
@@ -562,12 +522,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
562
522
  version: '0'
563
523
  required_rubygems_version: !ruby/object:Gem::Requirement
564
524
  requirements:
565
- - - ">="
525
+ - - ">"
566
526
  - !ruby/object:Gem::Version
567
- version: '0'
527
+ version: 1.3.1
568
528
  requirements: []
569
529
  rubyforge_project:
570
- rubygems_version: 2.5.1
530
+ rubygems_version: 2.4.8
571
531
  signing_key:
572
532
  specification_version: 4
573
533
  summary: CapistranoMulticonfigParallel is a simple ruby implementation that allows
@@ -1,132 +0,0 @@
1
- require_relative '../helpers/base_actor_helper'
2
- module CapistranoMulticonfigParallel
3
- # class that handles the rake task and waits for approval from the celluloid worker
4
- class RakeWorker
5
- include CapistranoMulticonfigParallel::BaseActorHelper
6
-
7
- attr_reader :client, :job_id, :action, :task,
8
- :task_approved, :successfull_subscription,
9
- :subscription_channel, :publisher_channel, :stdin_result
10
-
11
- def work(options = {})
12
- @options = options.stringify_keys
13
- default_settings
14
- custom_attributes
15
- initialize_subscription
16
- end
17
-
18
- def custom_attributes
19
- @publisher_channel = "worker_#{@job_id}"
20
- @action = @options['action'].present? ? @options['action'] : 'invoke'
21
- @task = @options['task']
22
- end
23
-
24
- def publish_new_work(new_options = {})
25
- work(@options.merge(new_options))
26
- publish_to_worker(task_data)
27
- end
28
-
29
- def wait_execution(name = task_name, time = 0.1)
30
- # info "Before waiting #{name}"
31
- Actor.current.wait_for(name, time)
32
- # info "After waiting #{name}"
33
- end
34
-
35
- def wait_for(_name, time)
36
- # info "waiting for #{time} seconds on #{name}"
37
- sleep time
38
- # info "done waiting on #{name} "
39
- end
40
-
41
- def default_settings
42
- @stdin_result = nil
43
- @job_id = @options['job_id']
44
- @subscription_channel = @options['actor_id']
45
- @task_approved = false
46
- @successfull_subscription = false
47
- end
48
-
49
- def initialize_subscription
50
- return if defined?(@client) && @client.present?
51
- @client = CelluloidPubsub::Client.new(actor: Actor.current, enable_debug: debug_websocket?, channel: @subscription_channel, log_file_path: websocket_config.fetch('log_file_path', nil))
52
- end
53
-
54
- def task_name
55
- @task.respond_to?(:name) ? @task.name : @task
56
- end
57
-
58
- def task_data
59
- {
60
- action: @action,
61
- task: task_name,
62
- job_id: @job_id
63
- }
64
- end
65
-
66
- def publish_to_worker(data)
67
- @client.publish(@publisher_channel, data)
68
- end
69
-
70
- def on_message(message)
71
- return unless message.present?
72
- log_to_file("Rake worker #{@job_id} received after on message:", message)
73
- if @client.succesfull_subscription?(message)
74
- publish_subscription_successfull(message)
75
- elsif message_is_about_a_task?(message)
76
- task_approval(message)
77
- elsif msg_for_stdin?(message)
78
- stdin_approval(message)
79
- else
80
- show_warning "unknown message: #{message.inspect}"
81
- end
82
- end
83
-
84
- def publish_subscription_successfull(message)
85
- return unless @client.succesfull_subscription?(message)
86
- log_to_file("Rake worker #{@job_id} received after publish_subscription_successfull:", message)
87
- @successfull_subscription = true
88
- publish_to_worker(task_data)
89
- end
90
-
91
- def wait_for_stdin_input
92
- wait_execution until @stdin_result.present?
93
- output = @stdin_result.clone
94
- @stdin_result = nil
95
- output
96
- end
97
-
98
- def stdin_approval(message)
99
- return unless msg_for_stdin?(message)
100
- if @job_id == message['job_id']
101
- @stdin_result = message.fetch('result', '')
102
- else
103
- show_warning "unknown stdin_approval #{message.inspect}"
104
- end
105
- end
106
-
107
- def task_approval(message)
108
- return unless message_is_about_a_task?(message)
109
- if @job_id == message['job_id'] && message['task'].to_s == task_name.to_s && message['approved'] == 'yes'
110
- @task_approved = true
111
- else
112
- show_warning "unknown task_approval #{message.inspect} #{task_data}"
113
- end
114
- end
115
-
116
- def on_close(code, reason)
117
- log_to_file("websocket connection closed: #{code.inspect}, #{reason.inspect}")
118
- terminate
119
- end
120
-
121
- def user_prompt_needed?(data)
122
- question, default = get_question_details(data)
123
- log_to_file("Rake worker #{@job_id} tries to determine question #{data.inspect} #{question.inspect} #{default.inspect}")
124
- return if question.blank? || @action != 'invoke'
125
- publish_to_worker(action: 'stdout',
126
- question: question,
127
- default: default.present? ? default.delete('()') : '',
128
- job_id: @job_id)
129
- wait_for_stdin_input
130
- end
131
- end
132
- end
@@ -1,34 +0,0 @@
1
- module CapistranoMulticonfigParallel
2
- # class used to hook into the input stream
3
- class InputStream
4
- def self.hook(actor, stringio)
5
- $stdin = new($stdin, actor, stringio)
6
- end
7
-
8
- def self.unhook
9
- $stdin.finish if $stdin.is_a? CapistranoMulticonfigParallel::InputStream
10
- $stdin = STDIN
11
- end
12
-
13
- attr_accessor :real, :actor, :stringio
14
-
15
- def initialize(real_stdin, actor, stringio)
16
- self.real = real_stdin
17
- self.actor = actor
18
- self.stringio = stringio
19
- end
20
-
21
- def gets(*_args)
22
- @stringio.rewind
23
- data = @stringio.read
24
- @actor.user_prompt_needed?(data)
25
- end
26
-
27
- def finish
28
- end
29
-
30
- def method_missing(name, *args, &block)
31
- @real.send name, *args, &block
32
- end
33
- end
34
- end
@@ -1,33 +0,0 @@
1
- module CapistranoMulticonfigParallel
2
- # class used to hook into the output stream
3
- class OutputStream
4
- def self.hook(stringio)
5
- $stdout = new($stdout, stringio)
6
- end
7
-
8
- def self.unhook
9
- $stdout.finish if $stdout.is_a? CapistranoMulticonfigParallel::OutputStream
10
- $stdout = STDOUT
11
- end
12
-
13
- attr_accessor :real, :stringio
14
-
15
- def initialize(real_stdout, stringio)
16
- self.real = real_stdout
17
- self.stringio = stringio
18
- end
19
-
20
- def write(*args)
21
- @stringio.write(*args)
22
- @real.write(*args)
23
- @real.flush
24
- end
25
-
26
- def finish
27
- end
28
-
29
- def method_missing(name, *args, &block)
30
- @real.send name, *args, &block
31
- end
32
- end
33
- end
@@ -1,88 +0,0 @@
1
- require_relative '../celluloid/rake_worker'
2
- require_relative './input_stream'
3
- require_relative './output_stream'
4
- require_relative '../helpers/application_helper'
5
- module CapistranoMulticonfigParallel
6
- # class used to handle the rake worker and sets all the hooks before and after running the worker
7
- class RakeTaskHooks
8
- include CapistranoMulticonfigParallel::ApplicationHelper
9
- attr_accessor :job_id, :task
10
- def initialize(task = nil)
11
- @job_id = CapistranoMulticonfigParallel.job_id
12
- @task = task.respond_to?(:fully_qualified_name) ? task.fully_qualified_name : task
13
- end
14
-
15
- def automatic_hooks(&block)
16
- if configuration.multi_secvential.to_s.downcase == 'false' && job_id.present? && @task.present?
17
- actor_start_working(action: 'invoke')
18
- actor.wait_execution until actor.task_approved
19
- actor_execute_block(&block)
20
- else
21
- block.call
22
- end
23
- end
24
-
25
- def print_question?(question)
26
- if job_id.present?
27
- actor.user_prompt_needed?(question)
28
- else
29
- yield if block_given?
30
- end
31
- end
32
-
33
- private
34
-
35
- def actor
36
- Celluloid::Actor[rake_actor_id]
37
- end
38
-
39
- def output_stream
40
- CapistranoMulticonfigParallel::OutputStream
41
- end
42
-
43
- def input_stream
44
- CapistranoMulticonfigParallel::InputStream
45
- end
46
-
47
- def before_hooks
48
- stringio = StringIO.new
49
- output = output_stream.hook(stringio)
50
- input = input_stream.hook(actor, stringio)
51
- [input, output]
52
- end
53
-
54
- def after_hooks
55
- input_stream.unhook
56
- output_stream.unhook
57
- end
58
-
59
- def actor_execute_block(&block)
60
- before_hooks
61
- block.call
62
- after_hooks
63
- end
64
-
65
- def actor_start_working(additionals = {})
66
- additionals = additionals.present? ? additionals : {}
67
- if actor.blank?
68
- supervise_actor
69
- actor.work({actor_id: rake_actor_id, job_id: job_id, task: @task}.merge(additionals))
70
- else
71
- actor.publish_new_work({task: @task}.merge(additionals))
72
- end
73
- end
74
-
75
- def supervise_actor
76
- return unless actor.blank?
77
- if CapistranoMulticonfigParallel::BaseActorHelper::ClassMethods.version_less_than_seventeen?
78
- CapistranoMulticonfigParallel::RakeWorker.supervise_as(rake_actor_id)
79
- else
80
- CapistranoMulticonfigParallel::RakeWorker.supervise(as: rake_actor_id)
81
- end
82
- end
83
-
84
- def rake_actor_id
85
- "rake_worker_#{job_id}"
86
- end
87
- end
88
- end