dimanche 17 janvier 2016

cannot load such file -- ./config/database.yml on rails

I have a file on path pbxapi_rails/lib/tasks/mon_batch_scripts.rake for deleting on my database.

but it says cannot load such file -- ./config/database.yml but i have the file . .

Why i am getting this error ? thanks

this is my code in pbxapi_rails/lib/tasks/mon_batch_scripts.rake

namespace :mon_batch_scripts do
  desc "Monthly Batch Scripts"
  task :mon_terminate_trunk2 => :environment do
    require "mysql2"
    require "./config/dbconfig.rb"
    logger = Logger.new("/var/pbxapi_rails/shared/log/cron.log")
    logger.info $db_sys3.inspect
    datenow = 1.month.ago.at_end_of_month.strftime('%Y-%m-%d 23:59:59')
    currentDate = DateTime.now.strftime('%Y-%m-%d %H:%M:%S')
    client = Mysql2::Client.new(:host => $db_sys3[:host], :username => $db_sys3[:username], :database => $db_sys3[:database], :password => $db_sys3[:password])
    logger.info "Trunk 2 Terminate Batch script started running: " + currentDate
    logger.info "Trunk 2 Terminate Batch date to delete: " + datenow
    date = client.escape(datenow)
    param = client.query("SELECT membId ,account_id FROM mst003  WHERE dataDeleteFlg = 1 AND DATE_FORMAT(dateDelete,'%Y-%m-%d %H:%i:%s') = '#{date}' GROUP BY account_id, membId")
    if param.size > 0
      begin
        param.each do |e1|
          accountId = client.escape(e1["account_id"])
          membId = client.escape(e1["membId"])

          #Trunk 2 Uniques
          @uniques = client.query("SELECT m3.`membUid` FROM mst003 m3 LEFT JOIN products p ON m3.membServiceKamokuId = p.product_code WHERE m3.account_id = '#{accountId}' AND m3.membId = '#{membId}' AND m3.dataDeleteFlg = 1 AND p.product_code = 'A09B' AND DATE_FORMAT(m3.dateDelete,'%Y-%m-%d %H:%i:%s') = '#{date}'")
          unique_param = Hash.new
          if @uniques.size > 0
            @uniques.each do |e1|
              params = Hash.new
              params[:id] = e1["membUid"]
              unique = Unique.new
              uniqueTerminate = unique.terminate(params)
              logger.info("#{uniqueTerminate.inspect}")
            end
          end #End of Trunk 2 Uniques
          #Trunk 2 Channels
          @channels = client.query("SELECT m3.membId FROM mst003 m3 LEFT JOIN products p ON m3.membServiceKamokuId = p.product_code WHERE m3.account_id = '#{accountId}' AND m3.membId = '#{membId}' AND m3.dataDeleteFlg = 1 AND p.product_code = 'A09C' AND DATE_FORMAT(m3.dateDelete,'%Y-%m-%d %H:%i:%s') = '#{date}'")
          channels_param = Hash.new
          if @channels.size > 0
            @channels.each do |e1|
              channels_param[:id] = e1["membId"]
              circle = Circle.find_by circle_number: channels_param[:id]
              if circle.present? == true
                uniques = UniqueSipTrunkSetting.find(:first, :conditions => ["uniques.circle_id = ?",circle.id], 
                 :joins => [:unique],
                 :select => 'SUM(unique_sip_trunk_settings.cannel_limit) as cannel_limit')
                logger.info circle.inspect
                circle[:trunk2_total_channels] -= 1
                circle.save
                cnt = uniques.cannel_limit - circle[:trunk2_total_channels]
                while cnt > 0
                  channel = UniqueSipTrunkSetting.find(:first, :conditions => ["uniques.circle_id = ?",circle.id],
                         :joins => [:unique],
                         :order => "cannel_limit DESC")
                  channel = UniqueSipTrunkSetting.find(channel.id)
                  channel[:cannel_limit] -= 1
                  channel.save 
                  cnt-=1
                end
              end
            end
          end
        end
        logger.info "Trunk 2 monthly batch termination script has been successfully executed"
      rescue => e
        logger.info "Error Terminating"
        logger.info e
      end
    end
  end #end task
end #end namespace

but when i run the script . I got this error.

[root@pbxapi-1-test current]# RAILS_ENV=production bundle exec rake mon_batch_scripts:mon_terminate_trunk2 —trace

rake aborted!

cannot load such file -- ./config/database.yml

/usr/local/rvm/gems/ruby-2.0.0-p643/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in require' /usr/local/rvm/gems/ruby-2.0.0-p643/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:inblock in require' /usr/local/rvm/gems/ruby-2.0.0-p643/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in load_dependency' /usr/local/rvm/gems/ruby-2.0.0-p643/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:inrequire' /var/pbxapi_rails/current/lib/tasks/mon_batch_scripts.rake:5:in block (2 levels) in <top (required)>' /usr/local/rvm/gems/ruby-2.0.0-p643/bin/ruby_executable_hooks:15:ineval' /usr/local/rvm/gems/ruby-2.0.0-p643/bin/ruby_executable_hooks:15:in `'

Aucun commentaire:

Enregistrer un commentaire