lib/i18n/migrations/migrator.rb in i18n-migrations-1.0.2 vs lib/i18n/migrations/migrator.rb in i18n-migrations-1.0.3

- old
+ new

@@ -9,11 +9,11 @@ require 'google_spreadsheet' require 'config' require 'locale' require 'migration_factory' -ASYNC = false +CONCURRENT_THREADS = 4 # this class knows how to do all the things the cli needs done. # it mostly delegates to locale to do it, often asking multiple locales to do the same thing module I18n module Migrations @@ -104,30 +104,34 @@ puts "#{locale.name}: #{locale.last_version}" end end def validate(locale_or_all) - each_locale(locale_or_all) do |locale| + each_locale(locale_or_all, async: false) do |locale| next if locale.main_locale? locale.update_info do |data, notes| locale.validate(data, notes) end end end private - def each_locale(name = 'all') + def each_locale(name = 'all', async: true) locale_names = name == 'all' ? all_locale_names : [name] - if ASYNC - threads = locale_names.map do |l| - locale = locale_for(l) - Thread.new {yield locale} + if async + locale_names.each_slice(CONCURRENT_THREADS) do |some_locale_names| + threads = some_locale_names.map do |l| + locale = locale_for(l) + Thread.new {yield locale} + end + threads.each(&:join) end - threads.each(&:join) else - locale_names.each {|l| yield locale_for(l)} + locale_names.each do |l| + yield locale_for(l) + end end end def all_locale_names [config.main_locale] + config.other_locales