Ruby on rails ActiveRecord任务在错误的环境中执行

Ruby on rails ActiveRecord任务在错误的环境中执行,ruby-on-rails,activerecord,whenever,Ruby On Rails,Activerecord,Whenever,我必须在ActiveRecord数据库中运行一个涉及一些数据清理的Cron任务。我在用宝石。代码如下: 附表1.rb 每1.5小时执行一次 rake“通知:清除” 结束 通知。rake 名称空间:通知不起作用 任务清除::环境做什么 Rpush::Notification.delete\u all 结束 结束 运行此命令会导致以下错误: rake aborted! ActiveRecord::NoDatabaseError: FATAL: role "user_prod" does not

我必须在ActiveRecord数据库中运行一个涉及一些数据清理的Cron任务。我在用宝石。代码如下:

附表1.rb

每1.5小时执行一次
rake“通知:清除”
结束
通知。rake

名称空间:通知不起作用
任务清除::环境做什么
Rpush::Notification.delete\u all
结束
结束
运行此命令会导致以下错误:

rake aborted!
ActiveRecord::NoDatabaseError: FATAL:  role "user_prod" does not exist
我在开发环境。这是我的database.yml文件:

default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see Rails configuration guide
  # http://guides.rubyonrails.org/configuring.html#database-pooling
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: development_database

test:
  <<: *default
  database: test_database

staging:
  <<: *default
  database: staging_database
  username: user_staging
  password: <%= ENV['DATABASE_PASSWORD'] %>


production:
  <<: *default
  database: production_database
  username: user_prod
  password: <%= ENV['DATABASE_PASSWORD'] %>
default:&default
适配器:postgresql
编码:unicode
#有关连接池的详细信息,请参阅Rails配置指南
# http://guides.rubyonrails.org/configuring.html#database-汇集
游泳池:
发展:

使用以下内容更新您的代码:-

在schedule.rb文件中:-

every 1.hour do
  rake 'notifications:clear', :environment => "development"
end
最后执行了这个命令:-

whenever --update-crontab

清除现有的cron作业

crontab -r
使用环境更新cronjob

whenever --update-crontab --set environment='development'