fanforce-factory 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,128 @@
1
+ class Fanforce::Factory::Addon
2
+ attr_reader :_id, :type, :dir, :dir_name, :dir_root, :root_domain, :plugin_type
3
+
4
+ def self.parse_dir_name(dir_name)
5
+ return if dir_name !~ /^((app|plugin|widget)-(.+))\/?$/
6
+ {_id: $3, type: $2, dir_name: $1}
7
+ end
8
+
9
+ def self.load(dir, plugin_type=nil)
10
+ self.new(dir, plugin_type)
11
+ end
12
+
13
+ def initialize(dir, plugin_type)
14
+ raise "This is an invalid directory name for a factory addon: #{dir}" if dir !~ /^(.*)\/((app|plugin|widget)-([^\/]+))\/?$/
15
+
16
+ @_id = $4
17
+ @type = $3.to_sym
18
+ @dir = "#{$1}/#{$2}"
19
+ @dir_root = $1
20
+ @dir_name = $2
21
+ @root_domain = case @type when :app then $FF_APP_DOMAIN when :plugin then $FF_PLUGIN_DOMAIN when :widget then $FF_WIDGET_DOMAIN end
22
+ @plugin_type = (plugin_type.present?) ? plugin_type.to_sym : nil
23
+
24
+ if @type == :plugin and @plugin_type.blank?
25
+ raise "No config.ru was found in the home directory: #{dir}" if !File.exists?("#{dir}/config.ru")
26
+
27
+ File.open("#{@dir}/config.ru", 'r') do |f|
28
+ if f.read =~ /FanforcePlugin\.config.+config.type\s+=\W+(data_connector|data_processor|broadcaster|identifier|behavior)/m
29
+ @plugin_type = $1.to_sym
30
+ else
31
+ raise 'Factory plugins specify their type in the config.ru file'
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ def create_files(*filenames)
38
+ filenames.each do |filename|
39
+ Fanforce::Factory::Files.method(:"create_#{filename}").call(self)
40
+ end
41
+ end
42
+ alias create_file create_files
43
+
44
+ def update_files(*filenames)
45
+ filenames.each do |filename|
46
+ Fanforce::Factory::Files.method(:"update_#{filename}").call(self)
47
+ end
48
+ end
49
+ alias update_file update_files
50
+
51
+ def to_hash
52
+ {
53
+ _id: @_id,
54
+ type: @type,
55
+ dir_name: @dir_name,
56
+ dir_root: @dir_root,
57
+ dir: @dir,
58
+ plugin_type: @plugin_type,
59
+ }
60
+ end
61
+
62
+ def to_json
63
+ to_hash.to_json
64
+ end
65
+
66
+ def start_print
67
+ print "- #{@dir_name}... "
68
+ end
69
+
70
+ def end_print
71
+ puts 'DONE'
72
+ end
73
+
74
+ end
75
+
76
+ class Fanforce::Factory::Addons
77
+ require 'singleton'
78
+ require 'forwardable'
79
+ include Singleton
80
+
81
+ def dir_names
82
+ @dirs ||= Dir.chdir($HomeDir) do Dir['*/'].inject([]) do |dirs, d|
83
+ d = d.gsub('/', '')
84
+ next dirs if d !~ /^((app|plugin|widget)-(.+))\/?$/
85
+ next dirs << d if $Filter.blank?
86
+ next dirs << d if $Filter[:dir_name].present? and $Filter[:dir_name] == $1
87
+ if $Filter[:type] and $Filter[:type] == $2.to_sym and !$Filter[:plugin_type]
88
+ next dirs << d
89
+ elsif $Filter[:type] and $Filter[:type] == $2.to_sym and $Filter[:plugin_type]
90
+ next dirs if !File.exists?("#{$HomeDir}/#{$1}/config.ru")
91
+ File.open("#{$HomeDir}/#{$1}/config.ru", 'r') do |f|
92
+ if f.read =~ /FanforcePlugin\.config.+config.type\s+=\W+(data_connector|data_processor|broadcaster|identifier|behavior)/m
93
+ next dirs << d if $Filter[:plugin_type] == $1.to_sym
94
+ else
95
+ raise "#{d} is not correctly specifying its type in the config.ru file"
96
+ end
97
+ end
98
+ end
99
+ dirs
100
+ end end
101
+ end
102
+
103
+ def dirs
104
+ dir_names.inject([]) do |result, d|
105
+ result << "#{$HomeDir}/#{d}"
106
+ end
107
+ end
108
+
109
+ def each(&block)
110
+ cur_count = 0
111
+ total = dir_names.size
112
+ dir_names.each do |d|
113
+ cur_count += 1
114
+ addon = Fanforce::Factory::Addon.load("#{$HomeDir}/#{d}")
115
+ Dir.chdir(addon.dir) { block.call(addon, cur_count, total) }
116
+ end
117
+ end
118
+
119
+ def count
120
+ dir_names.size
121
+ end
122
+
123
+ class << self
124
+ extend Forwardable
125
+ def_delegators :instance, *Fanforce::Factory::Addons.instance_methods(false)
126
+ end
127
+
128
+ end
@@ -0,0 +1,449 @@
1
+ class Fanforce::Factory
2
+ require 'fanforce/factory/commands_support'
3
+
4
+ def create_addon(addon_type, addon_id, plugin_type=nil)
5
+ dir_name = "#{addon_type}-#{addon_id}"
6
+ dir = "#{$HomeDir}/#{dir_name}"
7
+
8
+ if File.exists?("#{dir}/config.ru")
9
+ puts '---------------------------------------------------------------------------------------------------------------'
10
+ puts 'ERROR... '.format(:red,:bold) + "#{addon_type}-#{addon_id} already exists. You should run: ".format(:red) + "factory update #{dir_name}".format(:green)
11
+ puts '---------------------------------------------------------------------------------------------------------------'
12
+ return
13
+ end
14
+
15
+ puts "\n---------------------------------------------------------------------------------------------------------------"
16
+ puts 'CREATING FILES...'
17
+ Dir.mkdir(dir) if !File.directory?(dir)
18
+ Dir.chdir(dir)
19
+ puts "#{'Created'.format(:bold, :green)} #{dir_name}/"
20
+ addon = Addon.load(dir, plugin_type)
21
+ setup_files(addon)
22
+
23
+ puts "\n---------------------------------------------------------------------------------------------------------------"
24
+ puts 'RUNNING BUNDLER...'
25
+ Run.bundle_install(addon.dir)
26
+
27
+ puts "\n---------------------------------------------------------------------------------------------------------------"
28
+ puts 'CREATING POW DOMAINS...'
29
+ setup_pow(addon)
30
+
31
+ puts "\n---------------------------------------------------------------------------------------------------------------"
32
+ puts 'CREATING LOCAL GIT REPOSITORY...'
33
+ Run.git_init and puts '- git init'
34
+ Run.git_add and puts '- git add .'
35
+ Run.git_first_commit and puts '- git commit -m "initial factory commit"'
36
+
37
+ puts "\n---------------------------------------------------------------------------------------------------------------"
38
+ puts 'CREATING BITBUCKET REPOSITORY...'
39
+ setup_bitbucket addon
40
+
41
+ puts "\n---------------------------------------------------------------------------------------------------------------"
42
+ puts 'CREATING HEROKU APPS...'
43
+ setup_heroku addon, :qa
44
+ setup_heroku addon, :production
45
+
46
+ puts "\n---------------------------------------------------------------------------------------------------------------"
47
+ puts 'CREATING ENV VARIABLES...'
48
+ setup_envs(addon, :all)
49
+
50
+ puts "\n---------------------------------------------------------------------------------------------------------------"
51
+ puts "#{'DONE!'.format(:bold,:green)} Paste the following JSON into your Developer Configuration for #{addon._id.format(:bold)}:"
52
+ puts '---------------------------------------------------------------------------------------------------------------'
53
+ puts DeveloperConfig.method(addon.type).call(addon).format(:magenta)
54
+ puts '---------------------------------------------------------------------------------------------------------------'
55
+ puts "\n"
56
+ end
57
+
58
+ ######################################################################################################################
59
+
60
+ def delete_addon(addon_type, addon_id)
61
+ dir_name = "#{addon_type}-#{addon_id}"
62
+ dir = "#{$HomeDir}/#{dir_name}"
63
+
64
+ if !File.directory?("#{dir}")
65
+ puts '---------------------------------------------------------------------------------------------------------------'
66
+ puts 'OOPS... '.format(:red,:bold) + "#{addon_type}-#{addon_id} does not exist and therefore cannot be deleted!"
67
+ puts '---------------------------------------------------------------------------------------------------------------'
68
+ return
69
+ end
70
+
71
+ addon = Addon.load(dir)
72
+
73
+ puts "\n---------------------------------------------------------------------------------------------------------------"
74
+ puts 'DELETING HEROKU APPS...'
75
+ [:qa,:production].each do |environment|
76
+ next if $Config[:heroku].blank? or $Config[:heroku][environment].blank?
77
+ heroku = auth_heroku(environment)
78
+ heroku_app_name = get_heroku_app_name(addon, environment)
79
+ #begin
80
+ heroku.delete_app(heroku_app_name)
81
+ puts "#{'Removed '.format(:green,:bold)}" + " #{heroku_app_name}"
82
+ #rescue
83
+ # puts "#{'Already Removed'.format(:green,:bold)}" + " #{heroku_app_name}"
84
+ #end
85
+ end
86
+
87
+ puts "\n---------------------------------------------------------------------------------------------------------------"
88
+ puts 'DELETING BITBUCKET REPOSITORY...'
89
+ if $Config[:bitbucket].present?
90
+ bitbucket = BitBucket.new(login: $Config[:bitbucket][:user], password: $Config[:bitbucket][:password])
91
+ begin
92
+ repo = bitbucket.repos.find($Config[:bitbucket][:user], addon.dir_name)
93
+ RestClient.delete("https://#{$Config[:bitbucket][:user]}:#{$Config[:bitbucket][:password]}@api.bitbucket.org/1.0/repositories/#{$Config[:bitbucket][:user]}/#{addon.dir_name}")
94
+ puts "#{'Removed'.format(:green,:bold)}" + " #{addon.dir_name}"
95
+ rescue
96
+ puts "#{'Already Removed'.format(:green,:bold)}" + " #{addon.dir_name}"
97
+ end
98
+ end
99
+
100
+ puts "\n---------------------------------------------------------------------------------------------------------------"
101
+ puts 'DELETING POW DOMAINS...'
102
+ Run.pow_destroy(addon, addon.root_domain)
103
+ Run.pow_destroy(addon, $SMARTURL_DOMAIN) if addon.plugin_type == :behavior
104
+
105
+ puts "\n---------------------------------------------------------------------------------------------------------------"
106
+ puts 'DELETING FILES...'
107
+ if File.directory?(dir)
108
+ FileUtils.rm_rf(dir)
109
+ puts "#{'Removed'.format(:bold, :green)} #{dir_name}/"
110
+ else
111
+ puts "#{'Already Removed'.format(:bold, :green)} #{dir_name}/"
112
+ end
113
+
114
+ puts "\n---------------------------------------------------------------------------------------------------------------"
115
+ puts 'DONE! (note: iron workers were not deleted'
116
+ puts '---------------------------------------------------------------------------------------------------------------'
117
+
118
+ end
119
+
120
+ ######################################################################################################################
121
+
122
+ def run_setup(addon_dir, processed_count, total_count, scope, environment=:all)
123
+ addon = Addon.load(addon_dir)
124
+ puts "\n---------------------------------------------------------------------------------------------------------------"
125
+ puts "#{addon.type.to_s.upcase.format(:bold)} - #{addon._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... "
126
+
127
+ Dir.chdir(addon_dir) do
128
+ if [:all, :file].include?(scope)
129
+ puts ''
130
+ puts 'SETTING UP FILES...'
131
+ setup_files addon
132
+ end
133
+
134
+ if [:all, :pow].include?(scope)
135
+ puts ''
136
+ puts 'SETTING UP POW DOMAINS...'
137
+ setup_pow addon
138
+ end
139
+
140
+ if [:all, :bitbucket, :heroku].include?(scope)
141
+ puts ''
142
+ print 'ENSURING LOCAL GIT REPOSITORY EXISTS... '
143
+ if `git status`.include?('Not a git repository')
144
+ puts ''
145
+ Run.git_init and puts '- git init'
146
+ Run.git_add and puts '- git add .'
147
+ Run.git_first_commit and puts '- git commit -m "initial factory commit"'
148
+ puts ''
149
+ else
150
+ puts 'Found'
151
+ end
152
+ end
153
+
154
+ if [:all, :bitbucket].include?(scope)
155
+ puts ''
156
+ puts 'SETTING UP BITBUCKET REPOSITORY...'
157
+ setup_bitbucket addon
158
+ end
159
+
160
+ if [:all, :heroku].include?(scope)
161
+ puts ''
162
+ puts 'SETTING UP HEROKU APPS...'
163
+ setup_heroku addon, :qa if [:all,:qa].include?(environment)
164
+ setup_heroku addon, :production if [:all,:production].include?(environment)
165
+ end
166
+
167
+ if [:all, :env].include?(scope)
168
+ puts ''
169
+ puts 'SETTING UP ENV VARIABLES...'
170
+ setup_envs addon, environment
171
+ end
172
+
173
+ end
174
+ end
175
+
176
+ ######################################################################################################################
177
+
178
+ def run_update(addon_dir, processed_count, total_count, scope, environment)
179
+ addon = Addon.load(addon_dir)
180
+ puts "\n---------------------------------------------------------------------------------------------------------------"
181
+ puts "#{addon.type.to_s.upcase.format(:bold)} - #{addon._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... "
182
+
183
+ Dir.chdir(addon_dir) do
184
+ if [:all, :file].include?(scope)
185
+ puts ''
186
+ puts 'UPDATING FILES...'
187
+ setup_files addon
188
+ end
189
+
190
+ if [:all, :pow].include?(scope)
191
+ puts ''
192
+ puts 'UPDATING POW DOMAINS...'
193
+ setup_pow addon
194
+ end
195
+
196
+ if [:all, :bitbucket, :heroku].include?(scope)
197
+ puts ''
198
+ print 'ENSURING LOCAL GIT REPOSITORY EXISTS... '
199
+ if `git status`.include?('Not a git repository')
200
+ puts ''
201
+ Run.git_init and puts '- git init'
202
+ Run.git_add and puts '- git add .'
203
+ Run.git_first_commit and puts '- git commit -m "initial factory commit"'
204
+ puts ''
205
+ else
206
+ puts 'Found'
207
+ end
208
+ end
209
+
210
+ if [:all, :bitbucket].include?(scope)
211
+ puts ''
212
+ puts 'UPDATING BITBUCKET REPOSITORY...'
213
+ setup_bitbucket addon
214
+ end
215
+
216
+ if [:all, :heroku].include?(scope)
217
+ puts ''
218
+ puts 'UPDATING HEROKU APPS...'
219
+ setup_heroku addon, :qa if [:all,:qa].include?(environment)
220
+ setup_heroku addon, :production if [:all,:production].include?(environment)
221
+ end
222
+
223
+ if [:all, :env].include?(scope)
224
+ puts ''
225
+ puts 'UPDATING ENV VARIABLES...'
226
+ setup_envs addon, environment
227
+ end
228
+ end
229
+ end
230
+
231
+ ######################################################################################################################
232
+
233
+ def run_push(addon_dir, processed_count, total_count, environment, command, subcommand)
234
+ addon = Addon.load(addon_dir)
235
+ puts "\n---------------------------------------------------------------------------------------------------------------"
236
+ puts "#{addon.type.to_s.upcase.format(:bold)} - #{addon._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... "
237
+
238
+ Dir.chdir(addon_dir) do
239
+
240
+ if [:all,:bitbucket].include?(command) and $Config[:bitbucket].present?
241
+ puts "\n#{'Pushing '.format(:green,:bold)}" + "latest commit to Bitbucket (#{$Config[:bitbucket][:user]})..."
242
+ Run.command("git push #{$Config[:bitbucket][:user]} --all")
243
+ end
244
+
245
+ if [:all,:heroku].include?(command) and environment != :development
246
+ vars = Env.vars_by_addon(environment)[addon.dir_name] || {}
247
+ puts "\n#{"Updating Env Vars".format(:green,:bold)} on Heroku #{environment.to_s.titleize} (#{vars.size} variables)..."
248
+ push_env_to(environment, addon, vars)
249
+
250
+ remote_name = "#{environment==:qa ? 'qa' : 'prd'}-heroku"
251
+ puts "\n#{'Pushing '.format(:green,:bold)}" + "latest commit to Heroku #{environment.to_s.titleize} (#{remote_name})..."
252
+ Run.command("git push #{remote_name} master")
253
+ end
254
+
255
+ if [:all,:iron].include?(command)
256
+ puts ''
257
+ upload_iron(addon, command, [environment])
258
+ end
259
+
260
+ end
261
+ end
262
+
263
+ ######################################################################################################################
264
+
265
+ def count
266
+ puts '---------------------------------------------------------------------------------------------------------------'
267
+ puts "#{Addons.count} #{(($Filter.blank? or $Filter[:type].blank?) ? 'addons' : $Filter[:type]).to_s.pluralize}".format(:bold,:green) + ' were found in this directory.'
268
+ puts '---------------------------------------------------------------------------------------------------------------'
269
+ puts ''
270
+ end
271
+
272
+ ######################################################################################################################
273
+
274
+ def run_restart(addon_dir, processed_count, total_count, environment)
275
+ addon = Addon.load(addon_dir)
276
+ puts "---------------------------------------------------------------------------------------------------------------"
277
+ Dir.chdir(addon_dir) do
278
+ if [:all, :development].include?(environment)
279
+ puts "#{'DEVELOPMENT '.format(:bold)}#{addon.dir_name.format(:green)} restarted" if restart(addon, :development)
280
+ end
281
+ if [:all, :qa].include?(environment)
282
+ puts "#{'QA '.format(:bold)}#{addon.dir_name.format(:green)} restarted" if restart(addon, :qa)
283
+ end
284
+ if [:all, :production].include?(environment)
285
+ puts "#{'PRODUCTION '.format(:bold)}#{addon.dir_name.format(:green)} restarted" if restart(addon, :production)
286
+ end
287
+ end
288
+ end
289
+
290
+ def restart(addon, environment)
291
+ if environment == :development
292
+ `touch tmp/restart.txt`
293
+ elsif [:production, :qa].include?(environment)
294
+ if $Config[:heroku].blank? or $Config[:heroku][environment].blank?
295
+ puts "#{'OOPS...'.format(:red,:bold)} #{environment} has not been setup on heroku"
296
+ return false
297
+ end
298
+ heroku = auth_heroku(environment)
299
+ heroku.post_ps_restart get_heroku_app_name(addon, environment)
300
+ end
301
+ return true
302
+ end
303
+
304
+ ######################################################################################################################
305
+
306
+ def run_bundle(addon_dir, processed_count, total_count, arg, extra_args)
307
+ addon = Addon.load(addon_dir)
308
+ puts "\n---------------------------------------------------------------------------------------------------------------"
309
+ puts "#{addon.type.to_s.upcase.format(:bold)} - #{addon._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... "
310
+
311
+ Dir.chdir(addon_dir) do
312
+ if Gem::Specification::find_all_by_name('bundler').empty?
313
+ puts 'Installing Bundler... '
314
+ `gem install bundler`
315
+ puts 'DONE'
316
+ end
317
+
318
+ addon.update_file(:gemfile)
319
+ Run.command("bundle #{arg} #{extra_args.join(' ')}")
320
+ restart(addon, :development)
321
+ puts 'DONE'.format(:green)
322
+ end
323
+ end
324
+
325
+ ######################################################################################################################
326
+
327
+ def preprocess_git_overview
328
+ puts ''
329
+ length = Addons.dir_names.inject(0) {|length, dir_name| dir_name.length > length ? dir_name.length : length }
330
+ puts sprintf("%-#{length+3}s %-20s %s", 'Directory', 'Plugin Type', 'Status').format(:bold)
331
+ length
332
+ end
333
+
334
+ def postprocess_git_overview
335
+ puts '------------------------------------------------------------------------'
336
+ puts 'DONE'
337
+ end
338
+
339
+ def run_git_overview(addon_dir, processed_count, total_count, length)
340
+ addon = Addon.load(addon_dir)
341
+ puts '------------------------------------------------------------------------'
342
+ committed = Run.command('git status').include?('nothing to commit') ? true : false
343
+ printf "%-#{length+3}s %-20s %s\n", addon.dir_name, addon.type==:plugin ? addon.plugin_type : 'n/a', committed ? 'Committed'.format(:green) : 'Uncommitted'.format(:red)
344
+ end
345
+
346
+ def run_git(addon_dir, processed_count, total_count, extra_args)
347
+ addon = Addon.load(addon_dir)
348
+ puts "\n---------------------------------------------------------------------------------------------------------------"
349
+ puts "#{addon.type.to_s.upcase.format(:bold)} - #{addon._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... "
350
+
351
+ extra_args = extra_args.map {|c| c.include?(' ') ? c.to_json : c }.join(' ')
352
+ extra_args = '--no-pager ' + extra_args if extra_args !~ /--no-pager/
353
+
354
+ Dir.chdir(addon_dir) do
355
+ Run.command("git #{extra_args}")
356
+ puts 'DONE'.format(:green)
357
+ end
358
+ end
359
+
360
+ ######################################################################################################################
361
+
362
+ require 'iron_worker_ng'
363
+ def run_iron(addon_dir, processed_count, total_count, command, environment)
364
+ environments = environment == :all ? [:development, :qa, :production] : [environment]
365
+ addon = Addon.load(addon_dir)
366
+ puts "\n---------------------------------------------------------------------------------------------------------------"
367
+ puts "#{addon.type.to_s.upcase.format(:bold)} - #{addon._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... "
368
+
369
+ push_iron(addon, command, environments)
370
+ end
371
+
372
+ def upload_iron(addon, command, environments)
373
+ if !File.directory?("#{addon.dir}/workers")
374
+ return puts "#{'Skipped '.format(:bold)} no workers folder was found"
375
+ end
376
+
377
+ environments.each do |environment|
378
+ vars = Env.vars_by_addon(environment)[addon.dir_name]
379
+ has_workers = File.directory?("#{addon.dir}/workers") ? true : false
380
+
381
+ 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?
382
+
383
+ vars = {} if vars.blank?
384
+ puts "#{'Updating Env'.format(:green,:bold)} #{environment.to_s.titleize}#{has_workers ? '... and workers have' : 'has'} #{vars.size} env variables"
385
+ push_env_to(environment, addon, vars, true)
386
+
387
+ iron_worker = IronWorkerNG::Client.new(:token => vars['iron_token'], :project_id => vars['iron_project_id'])
388
+ Dir.chdir("#{addon.dir}/workers") do
389
+ workers = Dir["*.worker"]
390
+ next puts "#{'Skipped '.format(:bold)} #{environment.to_s.titleize} has 0 workers" if workers.size == 0
391
+
392
+ workers.each do |filename|
393
+ code_name = "#{addon._id}-#{filename.gsub('.worker', '')}"
394
+ remove_single_worker(code_name, iron_worker) if command == :reset
395
+
396
+ puts "#{'Uploading'.format(:green,:bold)} #{addon._id}-#{filename.gsub('.worker', '')} to #{environment.to_s.titleize}..."
397
+ code = IronWorkerNG::Code::Base.new(:workerfile => "#{addon.dir}/workers/#{filename}")
398
+ code.name = code_name
399
+ code.file("#{addon.dir}/workers/.#{addon.type}env.rb")
400
+ iron_worker.codes.create(code, max_concurrency: 5)
401
+ end
402
+ end
403
+ end
404
+ end
405
+
406
+ def remove_single_worker(code_name, iron_worker)
407
+ iron_worker.codes.list.each do |code|
408
+ next if code.name != code_name
409
+ iron_worker.codes.delete(code.id)
410
+ puts "#{'Removing '.format(:green,:bold)} #{addon._id}-#{filename.gsub('.worker', '')} from #{environment.to_s.titleize}..."
411
+ return true
412
+ end
413
+ end
414
+
415
+ ######################################################################################################################
416
+
417
+ def delete_all_iron_workers(environment)
418
+ puts ''
419
+ environments = environment == :all ? [:development, :qa, :production] : [environment]
420
+
421
+ iron_auths = {}
422
+ Addons.each do |addon, cur_count, total|
423
+ environments.each do |environment|
424
+ vars = Env.vars_by_addon(environment)[addon.dir_name]
425
+ iron_auths[environment] ||= {}
426
+ iron_auths[environment][vars['iron_project_id']] = vars['iron_token'] if vars['iron_project_id'].present?
427
+ end
428
+ end
429
+
430
+ environments.each do |environment|
431
+ puts '---------------------------------------------------------------------------------------------------------------'
432
+ puts "REMOVING WORKERS IN #{environment.to_s.upcase}..."
433
+
434
+ workers_found = false
435
+ iron_auths[environment].each do |iron_project_id, iron_token|
436
+ iron_worker = IronWorkerNG::Client.new(:token => iron_token, :project_id => iron_project_id)
437
+ iron_worker.codes.list.each do |code|
438
+ workers_found = true
439
+ iron_worker.codes.delete(code.id)
440
+ puts "#{'Removed'.format(:red,:bold)} #{code.name}"
441
+ end
442
+ end
443
+ puts 'No workers were found' if !workers_found
444
+ end
445
+
446
+ puts '---------------------------------------------------------------------------------------------------------------'
447
+ end
448
+
449
+ end