diff options
Diffstat (limited to 'lib/tasks')
| -rw-r--r-- | lib/tasks/cleanup.rake | 20 | ||||
| -rw-r--r-- | lib/tasks/config_files.rake | 37 | ||||
| -rw-r--r-- | lib/tasks/stats.rake | 4 | 
3 files changed, 45 insertions, 16 deletions
diff --git a/lib/tasks/cleanup.rake b/lib/tasks/cleanup.rake new file mode 100644 index 000000000..9a8be9521 --- /dev/null +++ b/lib/tasks/cleanup.rake @@ -0,0 +1,20 @@ +namespace :cleanup do + +  desc 'Clean up all message redelivery and destroy actions from the holding pen to make admin actions there faster' +  task :holding_pen => :environment do +    dryrun = ENV['DRYRUN'] != '0' +    if dryrun +        $stderr.puts "This is a dryrun - nothing will be deleted" +    end +    holding_pen = InfoRequest.find_by_url_title('holding_pen') +    old_events = holding_pen.info_request_events.find_each(:conditions => ['event_type in (?)', +                                                      ['redeliver_incoming', +                                                      'destroy_incoming']]) do |event| +      puts event.inspect +      if ! dryrun +        event.destroy +      end +    end +  end + +end diff --git a/lib/tasks/config_files.rake b/lib/tasks/config_files.rake index d0e4001f0..5dda64a04 100644 --- a/lib/tasks/config_files.rake +++ b/lib/tasks/config_files.rake @@ -23,26 +23,34 @@ namespace :config_files do      desc 'Convert Debian .ugly init script in config to a form suitable for installing in /etc/init.d'      task :convert_init_script => :environment do -        example = 'rake config_files:convert_init_script DEPLOY_USER=deploy VHOST_DIR=/dir/above/alaveteli SCRIPT_FILE=config/alert-tracks-debian.ugly ' -        check_for_env_vars(['DEPLOY_USER', 'VHOST_DIR', 'SCRIPT_FILE'], example) +        example = 'rake config_files:convert_init_script DEPLOY_USER=deploy VHOST_DIR=/dir/above/alaveteli VCSPATH=alaveteli SITE=alaveteli SCRIPT_FILE=config/alert-tracks-debian.ugly' +        check_for_env_vars(['DEPLOY_USER', +                            'VHOST_DIR', +                            'SCRIPT_FILE'], example) + +        replacements = { +            :user => ENV['DEPLOY_USER'], +            :vhost_dir => ENV['VHOST_DIR'], +            :vcspath => ENV.fetch('VCSPATH') { 'alaveteli' }, +            :site => ENV.fetch('SITE') { 'foi' } +        } -        deploy_user = ENV['DEPLOY_USER'] -        vhost_dir = ENV['VHOST_DIR'] -        script_file = ENV['SCRIPT_FILE'] +        # Use the filename for the $daemon_name ugly variable +        daemon_name = File.basename(ENV['SCRIPT_FILE'], '-debian.ugly') +        replacements.update(:daemon_name => "#{ replacements[:site] }-#{ daemon_name }") -        replacements = { :user => deploy_user, -                         :vhost_dir => vhost_dir } +        # Generate the template for potential further processing +        converted = convert_ugly(ENV['SCRIPT_FILE'], replacements) -        daemon_name = File.basename(script_file, '-debian.ugly') -        replacements.update(:daemon_name => "foi-#{daemon_name}") -        converted = convert_ugly(script_file, replacements) -        rails_env_file = File.expand_path(File.join(Rails.root, 'config', 'rails_env.rb')) -        if !File.exists?(rails_env_file) +        # gsub the RAILS_ENV in to the generated template if its not set by the +        # hard coded config file +        unless File.exists?("#{ Rails.root }/config/rails_env.rb")              converted.each do |line|                  line.gsub!(/^#\s*RAILS_ENV=your_rails_env/, "RAILS_ENV=#{Rails.env}")                  line.gsub!(/^#\s*export RAILS_ENV/, "export RAILS_ENV")              end          end +          converted.each do |line|              puts line          end @@ -50,7 +58,7 @@ namespace :config_files do      desc 'Convert Debian .ugly crontab file in config to a form suitable for installing in /etc/cron.d'      task :convert_crontab => :environment do -        example = 'rake config_files:convert_crontab DEPLOY_USER=deploy VHOST_DIR=/dir/above/alaveteli VCSPATH=alaveteli SITE=alaveteli CRONTAB=config/crontab-example' +        example = 'rake config_files:convert_crontab DEPLOY_USER=deploy VHOST_DIR=/dir/above/alaveteli VCSPATH=alaveteli SITE=alaveteli CRONTAB=config/crontab-example MAILTO=cron-alaveteli@example.org'          check_for_env_vars(['DEPLOY_USER',                              'VHOST_DIR',                              'VCSPATH', @@ -60,7 +68,8 @@ namespace :config_files do              :user => ENV['DEPLOY_USER'],              :vhost_dir => ENV['VHOST_DIR'],              :vcspath => ENV['VCSPATH'], -            :site => ENV['SITE'] +            :site => ENV['SITE'], +            :mailto => ENV.fetch('MAILTO') { "cron-#{ ENV['SITE'] }@mysociety.org" }          }          convert_ugly(ENV['CRONTAB'], replacements).each do |line|              puts line diff --git a/lib/tasks/stats.rake b/lib/tasks/stats.rake index f09594529..46a645b4d 100644 --- a/lib/tasks/stats.rake +++ b/lib/tasks/stats.rake @@ -119,7 +119,7 @@ DESC                      count ? count : 0                  end -      row = [body.name] + stats +      row = [%Q("#{ body.name }")] + stats        puts row.join(",")      end    end @@ -147,7 +147,7 @@ DESC                    count ? count : 0                end -      row = [body.name] + stats +      row = [%Q("#{ body.name }")] + stats        puts row.join(",")      end    end  | 
