Commit ad1d95f2251a9013d9d2728b3884ce04bc639902
1 parent
d70378c3
Exists in
staging
and in
42 other branches
ActionItem862: one enterprise at a time
This way we don't have a memory leak and can do one single loop to all enterprises.
Showing
2 changed files
with
17 additions
and
10 deletions
Show diff stats
script/apply-template
| ... | ... | @@ -8,9 +8,21 @@ env = Environment.default |
| 8 | 8 | |
| 9 | 9 | case $ARGV[0] |
| 10 | 10 | when 'inactive-enterprise' |
| 11 | - inactive_enterprises = Enterprise.find(:all, :conditions => {:enabled => false}) - [env.inactive_enterprise_template, env.enterprise_template] | |
| 12 | - apply_in = inactive_enterprises[$ARGV[1].to_i..$ARGV[2].to_i] | |
| 13 | - apply_in.each_with_index { |obj,i| obj.apply_template(env.inactive_enterprise_template); puts i.to_s + ' - ' + obj.identifier} unless apply_in.nil? | |
| 11 | + offset = 0 | |
| 12 | + excluded = [env.inactive_enterprise_template, env.enterprise_template] | |
| 13 | + template = excluded.first | |
| 14 | + | |
| 15 | + while enterprise = Enterprise.find(:first, :conditions => {:enabled => false}, :offset => offset) | |
| 16 | + # do nothing with templates | |
| 17 | + next if excluded.include?(enterprise) | |
| 18 | + | |
| 19 | + # do the thing | |
| 20 | + enterprise.apply_template(template) | |
| 21 | + puts "#{offset} - #{enterprise.identifier}" | |
| 22 | + | |
| 23 | + # bring it on ... | |
| 24 | + offset = offset + 1 | |
| 25 | + end | |
| 14 | 26 | when 'active-enterprise' |
| 15 | 27 | active_enterprises = Enterprise.find(:all, :conditions => {:enabled => true}) - [env.enterprise_template, env.enterprise_template] |
| 16 | 28 | active_enterprises.each { |enterprise| enterprise.apply_template(env.enterprise_template) } | ... | ... |
script/release-v0.13.0-ecosol
| ... | ... | @@ -58,13 +58,8 @@ script/runner 'env = Environment.default |
| 58 | 58 | main.blocks << MainBlock.new |
| 59 | 59 | template.save!' |
| 60 | 60 | |
| 61 | -echo 'Applying template for inactive enterprises (require bc calculator)...' | |
| 62 | -start=0; | |
| 63 | -for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21; do | |
| 64 | - end=`echo "$i * 1000" | bc`; | |
| 65 | - script/apply-template 'inactive-enterprise' $start $end; | |
| 66 | - start=$end; | |
| 67 | -done | |
| 61 | +echo 'Applying template for inactive enterprises' | |
| 62 | +script/apply-template 'inactive-enterprise' | |
| 68 | 63 | |
| 69 | 64 | echo 'Applying template for active enterprises...' |
| 70 | 65 | script/apply-template 'active-enterprise' | ... | ... |