fanforce-factory 0.5.0 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OGFhMjg0MTU4YzQ2NDVkNzk4YWE3MzViMDFhZDgzZWJhMzg4MWNkYg==
4
+ MjZkZGNhNzQ3NjQyNmJjMmZkYjhmMWQ4MzkxNmEzZWY4ZDgwMzNmOQ==
5
5
  data.tar.gz: !binary |-
6
- NzgyMGE2NDg5NDNhZTg0ZDMzNTBkNjc3YzE1M2Y5NDIyNjM0ZTY0MA==
6
+ Nzk2NDhjOTc1N2I0YjdhYzQ4ZjY1MmZkNjk1NTNkYThhNDllYjhkZQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NDI2YWM0MTliMGVmOTk3OWExMjg1MzRlOWRkYmMyYzdmNjMzODc3ZWY5MzM5
10
- ZDhlNzk4YjcwYTZjZWY4NmY4ZmJlYWVmZGNkOWQyNTNlOWQ3OTc0OGM1YTEw
11
- N2M0MDNlM2VkOWVlYWMyMDgyMDMxN2ZiZmQyY2NhYTI4ZTg2NmI=
9
+ NWM0ODI2ZmEzZGQ0NjVmNzBhN2ViNGE5MzY3ZTY0MWM3N2RkNmFmMjhjY2Jl
10
+ MGM3OWMxZjgyMDQ3OWQ1OGIyMjFhNDMwYTVmNDgwZjA5ZTBmNjY1MDRkNzQw
11
+ NTYxZGZkMTQzYThmY2NjNTc1N2VhMTY0Mjg4OGJlZDE0MGQ1NDI=
12
12
  data.tar.gz: !binary |-
13
- NDg1NDQyNGFiMTIwNzA0ZmM4NDkzZWRlMTI3NTkzZTQwZTQ2ZTU0MGNmOGIx
14
- Y2RiNDUxMWQ4YWM4MGQ3ZDU4YTg4ZDRiMmFjMTBhZmQ4M2EzY2Y3MmE1ODIx
15
- Y2UxZmQzNzIwZDAyNzM3ODVmZTQ2YTgzMjViOGVkYTA5YTE2NzE=
13
+ ZDRkODQ1YjIzZTU2NTcyZWZkODFlOTU0ZDIxNTUyNTJiZTQ4OTVhY2Q5YzAy
14
+ ZWQwN2M5NTNiNjBmN2M0NGZiZDhlN2I1YmIyOTBjNzE4NjMyMmE3MGQ1ZmQy
15
+ MDNmYzUxNWRiYzA5ZWIxMjZiMWZjMGFmZTZkZDhkYTYzMDViMTg=
data/Gemfile CHANGED
@@ -1,4 +1,2 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
-
4
- gem 'iron_worker_ng', :path => '../../../Projects/iron_worker_ruby_ng'
@@ -202,8 +202,8 @@ class Fanforce::Factory
202
202
  end
203
203
  puts '---------------------------------------------------------------------------------------------------------------'
204
204
 
205
- #elsif ARGV[0] == 'upgrade'
206
- # factory.upgrade
205
+ elsif ARGV[0] == 'upgrade'
206
+ run(:upgrade)
207
207
 
208
208
  end
209
209
 
@@ -343,7 +343,8 @@ class Fanforce::Factory
343
343
 
344
344
  def restart(addon, environment)
345
345
  if environment == :development
346
- `touch tmp/restart.txt`
346
+ File.mkdir("#{addon.dir}/tmp") if !File.directory?("#{addon.dir}/tmp")
347
+ FileUtils.touch("#{addon.dir}/tmp/touch.txt")
347
348
  elsif [:production, :staging].include?(environment)
348
349
  if $Config[:heroku].blank? or $Config[:heroku][environment].blank?
349
350
  puts "#{'OOPS...'.format(:red,:bold)} #{environment} has not been setup on heroku"
@@ -430,36 +431,44 @@ class Fanforce::Factory
430
431
  end
431
432
 
432
433
  environments.each do |environment|
433
- vars = Env.vars_by_addon(environment)[addon.dir_name]
434
+ vars = Env.vars_by_addon(environment)[addon.dir_name] || {}
434
435
  next puts "#{'Skipped '.format(:bold)} #{environment.to_s.titleize} is missing IRON_TOKEN and/or IRON_PROJECT_ID env variables" if vars['IRON_TOKEN'].blank? or vars['IRON_PROJECT_ID'].blank?
435
436
 
436
- vars = {} if vars.blank?
437
437
  puts "#{'Updating Env'.format(:green,:bold)} #{environment.to_s.titleize}... and workers have #{vars.size} env variables"
438
438
  push_env_to(environment, addon, vars, true)
439
439
 
440
440
  iron_worker = IronWorkerNG::Client.new(:token => vars['IRON_TOKEN'], :project_id => vars['IRON_PROJECT_ID'])
441
441
  Dir.chdir("#{addon.dir}/workers") do
442
- workers = Dir["*.worker"]
442
+ workers = Dir['*.worker']
443
443
  next puts "#{'Skipped '.format(:bold)} #{environment.to_s.titleize} has 0 workers" if workers.size == 0
444
444
 
445
+ upload_processes = []
445
446
  workers.each do |filename|
446
447
  code_name = "#{addon._id}-#{filename.gsub('.worker', '')}"
447
448
  remove_single_worker(code_name, iron_worker, environment) if command == :reset
448
449
 
449
450
  puts "#{'Uploading'.format(:green,:bold)} #{addon._id}-#{filename.gsub('.worker', '')} to #{environment.to_s.titleize}..."
450
451
  code = IronWorkerNG::Code::Base.new(:workerfile => "#{addon.dir}/workers/#{filename}")
452
+ code.remote
451
453
  code.name = code_name
452
- code.file("#{addon.dir}/workers/.#{addon.type}env.rb")
453
- begin
454
- iron_worker.codes.create(code, max_concurrency: 5)
455
- rescue Exception => e
456
- puts "#{'Aborted '.format(:red,:bold)} upload of #{addon._id}-#{filename.gsub('.worker', '')} to #{environment.to_s.titleize}..."
457
- puts e.message
458
- puts e.backtrace
459
- puts ''
460
- end
454
+ code.file("#{addon.dir}/workers/.#{environment}env.rb")
461
455
 
456
+ upload_processes << upload_iron_worker(addon, iron_worker, code, filename, environment)
462
457
  end
458
+ upload_processes.each { |pid| Process.waitpid(pid) }
459
+ end
460
+ end
461
+ end
462
+
463
+ def upload_iron_worker(addon, iron_worker, code, filename, environment)
464
+ fork do
465
+ begin
466
+ iron_worker.codes.create(code, max_concurrency: 5)
467
+ rescue Exception => e
468
+ puts "#{'Aborted '.format(:red,:bold)} upload of #{addon._id}-#{filename.gsub('.worker', '')} to #{environment.to_s.titleize}..."
469
+ puts e.message
470
+ puts e.backtrace
471
+ puts ''
463
472
  end
464
473
  end
465
474
  end
@@ -507,4 +516,38 @@ class Fanforce::Factory
507
516
  puts '---------------------------------------------------------------------------------------------------------------'
508
517
  end
509
518
 
519
+ ######################################################################################################################
520
+ def get_heroku_app_qa_name(addon, environment)
521
+ heroku_app_name = "#{environment==:production ? 'prd' : 'qa'}-#{addon.dir_name}"
522
+ heroku_app_name.length > 30 ? heroku_app_name.gsub!(/(a|e|i|o|u)/, '') : heroku_app_name
523
+ end
524
+
525
+ def run_upgrade(addon_dir, processed_count, total_count)
526
+ environment = :qa
527
+ addon = Addon.load(addon_dir)
528
+ puts "\n---------------------------------------------------------------------------------------------------------------"
529
+ puts "#{addon.type.to_s.upcase.format(:bold)} - #{addon._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... "
530
+
531
+ heroku = auth_heroku(:staging)
532
+ heroku_app_name = get_heroku_app_qa_name(addon, environment)
533
+ begin
534
+ heroku.delete_app(heroku_app_name)
535
+ puts "#{'Deleted '.format(:green,:bold)}" + "#{environment} app on heroku (#{heroku_app_name})"
536
+ rescue
537
+ heroku.post_app(name: heroku_app_name)
538
+ puts "#{'Not Found '.format(:green,:bold)}" + "#{environment} on heroku (#{heroku_app_name})"
539
+ end
540
+
541
+ remote_name = "#{environment==:production ? 'prd' : 'qa'}-heroku"
542
+ if (`git remote`).split(/\r?\n/).include?(remote_name)
543
+ puts "#{'Removed '.format(:green,:bold)}" + "git remote for #{remote_name}"
544
+ `git remote rm #{remote_name}`
545
+ else
546
+ puts "#{'Not Found '.format(:green,:bold)}" + "git remote for #{remote_name}"
547
+ end
548
+
549
+
550
+ end
551
+
552
+
510
553
  end
@@ -154,8 +154,10 @@ class Fanforce::Factory
154
154
  ######################################################################################################################
155
155
 
156
156
  def push_env_to(environment, addon, vars, create_worker_env=true)
157
+ File.delete("#{addon.dir}/workers/.#{addon.type}env.rb") if File.exists?("#{addon.dir}/workers/.#{addon.type}env.rb")
158
+ File.delete("#{addon.dir}/workers/.prebuildgems") if File.exists?("#{addon.dir}/workers/.prebuildgems")
157
159
  vars.each {|k,v| puts " - #{k}" }
158
- File.open("#{addon.dir}/workers/.#{addon.type}env.rb", 'w') {|f| f.write convert_hash_to_ruby_env(vars) } if create_worker_env and File.directory?("#{addon.dir}/workers") and vars['IRON_PROJECT_ID']
160
+ File.open("#{addon.dir}/workers/.#{environment}env.rb", 'w') {|f| f.write convert_hash_to_ruby_env(vars) } if create_worker_env and File.directory?("#{addon.dir}/workers") and vars['IRON_PROJECT_ID']
159
161
  if environment == :development
160
162
  addon.update_file(:powenv)
161
163
  File.open("#{addon.dir}/.#{addon.type}env", 'w') {|f| f.write convert_hash_to_shell_env(vars) }
@@ -240,7 +240,7 @@ class Fanforce::Factory::Files
240
240
  end
241
241
 
242
242
  def self.gitignore_lines(addon_type=nil)
243
- %w(*.gem *.rbc .bundle .config coverage InstalledFiles lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp .idea/ .sass-cache/ .DS_STORE .powenv .pluginenv .pluginenv.rb .appenv.rb .appenv .widgetenv .widgetenv.rb .yardoc _yardoc doc/)
243
+ %w(*.gem *.rbc .bundle .config coverage InstalledFiles lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp .idea/ .sass-cache/ .DS_STORE .powenv .pluginenv .appenv .widgetenv .*env.rb .yardoc _yardoc doc/)
244
244
  end
245
245
 
246
246
  # .POWENV #######################################################################
@@ -1,5 +1,5 @@
1
1
  class Fanforce
2
2
  class Factory
3
- VERSION = '0.5.0'
3
+ VERSION = '0.5.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fanforce-factory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caleb Clark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-24 00:00:00.000000000 Z
11
+ date: 2013-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client