开发者

Rails - delete_all or destroy_all not working on production server but working fine in development server

开发者 https://www.devze.com 2023-03-20 21:33 出处:网络
I have a rails app where I need to periodically delete search logs from a model. For this I am using a rake task with the syntax model.destroy_开发者_StackOverflow中文版all, it is working fine in deve

I have a rails app where I need to periodically delete search logs from a model. For this I am using a rake task with the syntax model.destroy_开发者_StackOverflow中文版all, it is working fine in development server. However, nothing seems to be happening on production server.

Both development and production servers are using Ubuntu Server 10.04, Rails 3.0.7, Mysql Database. Did you face similar situation before?

Below is the rake task code:

task :cleansed_log => :environment do
raw_logs = Searchlog.find_by_sql("SELECT q from searchlogs")
flag = 0
pres_log, prev_log = "", ""
if raw_logs.count > 1
  raw_logs.each do |raw_log|

    if flag == 0
      prev_log = raw_log.q
      flag = 1

    else

      pres_log = raw_log.q
      if pres_log =~ /#{prev_log}/
        prev_log = pres_log

      else
        @cleansedlog = Cleansedlog.new(:keyword => prev_log)
        @cleansedlog.save

        prev_log = pres_log
      end

    end
  end
  @cleansedlog = Cleansedlog.new(:keyword => pres_log)
  @cleansedlog.save

  Searchlog.destroy_all

end

end

Below is the cron job which calls above rake task:

# Begin Whenever generated tasks for: cleansedlog
# 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/bash -l -c 'cd       /var/www/prodsite//releases/20110715035538 && RAILS_ENV=production rake cleansed_log -- silent >> /work/saptcodes/cron.log 2>&1'
# End Whenever generated tasks for: cleansedlog


I am not sure, but do you pass RAILS_ENV option to you rake task?

For example:

rake logs:destroy RAILS_ENV='production'


Can you try with

model.delete_all

Careful since this will not honor callbacks, dependent associations and goes straight to the database.

I have encountered similar behavior sometimes with destroy_all, especially in migrations.

0

精彩评论

暂无评论...
验证码 换一张
取 消