Rake task identifying the environment as development ruby and sinatra -


i have written scheduler using "whenever gem". 1 of scheduler runs rake task everyday. rake task calls method in model , performs activerecord operations.

everything works fine, activerecord connects "development" environment in database.yml file , connects development database while in production.

config/schedule.rb   set :output, "log/cron_log.log"  every 6.hours   rake "sidekiq:restart" end  every :day, :at => '01:00am'   rake 'prune_users:older_than_2months' end 

rakefile

require 'newrelic_rpm' require './app.rb' import './lib/tasks/sidekiq.rake' import './lib/tasks/reap_user.rake' import './models/exportuser.rb' 

/lib/tasks/reap_user.rake

require 'sinatra/activerecord' require 'sinatra/activerecord/rake'  namespace :prune_users    desc 'delete 2 months older users status non-active'   task :older_than_2months     exportuser.delete_users_b4_2months   end  end 

/models/exportuser.rb

class exportuser < activerecord::base   self.table_name = 'exportusers'    def self.delete_users_b4_2months     begin       @old_users = exportuser.where("status != ? , modified < ?", "active", 2.months.ago)       puts "count of users before 2 months non-active status on #{time.now}"       puts @old_users.count       @old_users.find_each |users|         users.destroy!       end     rescue => err       newrelic::agent.notice_error(err)     end   end  end 

everything works fine, in exportuser.rb, activerecord connects development database. how make connect production.?

your application should honour rack_env environment variable.

try issuing following command:

user@server $ rack_env=production rake prune_users:older_than_2months 

and verify whether connects production database. if does, need change whatever invokes scheduled jobs include rack_env environment variable


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -