简体   繁体   English

ActiveRecord :: StatementInvalid:PG :: UndefinedTable:错误:关系

[英]ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation

I'm having some trouble with whenever. 我在任何时候都遇到麻烦。 I created a rake task which work perfectly when I launch it myself: 我创建了一个rake任务,当我自己启动它时,它可以完美运行:

namespace :check do
    desc "check all services"
    task :all do
       Rake::Task["fb_ping:check"].invoke
       Rake::Task["lithium_ping:check"].invoke
       Rake::Task["algolia_ping:check"].invoke
     end
end

but when it goes through whenever: 但是,只要它通过以下任何时候:

set :output, {:error => "log/cron_error_log.log", :standard => "log/cron_log.log"}
every 2.minutes do
  rake 'check:all'
end

I get the following return in my log: 我在日志中得到以下返回:

    rake aborted!
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "services" does not exist
LINE 1: SELECT "services".* FROM "services"
                                 ^
: SELECT "services".* FROM "services"
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/connection_adapters/postgresql_adapter.rb:598:in `async_exec'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/connection_adapters/postgresql_adapter.rb:598:in `block in exec_no_cache'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/connection_adapters/abstract_adapter.rb:590:in `block in log'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activesupport-5.0.6/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/connection_adapters/abstract_adapter.rb:583:in `log'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/connection_adapters/postgresql_adapter.rb:598:in `exec_no_cache'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/connection_adapters/postgresql_adapter.rb:585:in `execute_and_clear'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:103:in `exec_query'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/connection_adapters/abstract/database_statements.rb:377:in `select_prepared'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/connection_adapters/abstract/database_statements.rb:39:in `select_all'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/connection_adapters/abstract/query_cache.rb:95:in `select_all'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/querying.rb:39:in `find_by_sql'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/relation.rb:706:in `exec_queries'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/relation.rb:583:in `load'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/relation.rb:260:in `records'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/relation/delegation.rb:38:in `each'
/Users/Naekh/code/yoando/statuschecker/statuschecker/lib/tasks/fb_ping.rake:5:in `block (2 levels) in <top (required)>'
/Users/Naekh/code/yoando/statuschecker/statuschecker/lib/tasks/rake_them_all.rake:4:in `block (2 levels) in <top (required)>'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/rake-12.1.0/exe/rake:27:in `<top (required)>'
/Users/Naekh/.rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `eval'
/Users/Naekh/.rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `<main>'

I don't get how something that works independently can crash when called by whenever 我不知道独立工作的东西何时被任何人调用会崩溃

// Here is my schema: //这是我的架构:

ActiveRecord::Schema.define(version: 20170922073721) do

  enable_extension "plpgsql"

  create_table "pings", force: :cascade do |t|
    t.boolean  "up"
    t.integer  "service_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["service_id"], name: "index_pings_on_service_id", using: :btree
  end

  create_table "services", force: :cascade do |t|
    t.string   "name"
    t.string   "web_api"
    t.string   "json_path"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  add_foreign_key "pings", "services"
end

here is a ping check (fb_ping.rake), I used the same syntax in my other test. 这是一个ping检查(fb_ping.rake),我在其他测试中使用了相同的语法。 All of them work when I launch it manually : 当我手动启动它们时,它们都可以工作:

namespace :fb_ping do
desc "New fb ping"
task check: :environment do

  Service.all.each do | s |
    if s.name == 'Facebook'
      if FacebookStatusService.status === 1
        Ping.create(up: true, service: s)
        puts  'FB service is up'
      else
        Ping.create(up: false, service: s)
        puts  'FB service is down'
      end
    end
  end
end

end 结束

If a :path is not set it will default to the directory in which whenever was executed. 如果未设置:path,则默认为执行目录的目录。 :environment_variable will default to 'RAILS_ENV'. :environment_variable将默认为'RAILS_ENV'。 :environment will default to 'production'. :environment将默认为“生产”。 https://github.com/javan/whenever https://github.com/javan/无论何时

To adjust for the environment dynamically, you will need to pass variables on the fly. 要动态调整环境,您将需要即时传递变量。 https://github.com/javan/whenever/wiki/Setting-variables-on-the-fly https://github.com/javan/whenever/wiki/Setting-variables-on-the-fly

As a first test, try to hardcode your current environment, I'm assuming development in the example below: 作为第一个测试,请尝试对您的当前环境进行硬编码,在下面的示例中,我假设进行开发:

set :output, {:error => "log/cron_error_log.log", :standard => "log/cron_log.log"}
every 2.minutes do
  rake 'check:all', :environment => 'development'
end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ActiveRecord :: StatementInvalid:PG :: UndefinedTable:错误:关系“选项”不存在 - ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation “options” does not exist ActiveRecord::StatementInvalid: PG::UndefinedTable: 错误: 关系“人”不存在 - ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation “people” does not exist ActiveRecord :: StatementInvalid:PG :: UndefinedTable:错误:与HABTM与rails关联的关系 - ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation with HABTM association with rails ActiveRecord :: StatementInvalid(PG :: UndefinedTable:错误:关系“来宾簿”不存在 - ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation “guestbooks” does not exist ActiveRecord :: StatementInvalid:PG :: UndefinedTable:错误:关系“类别”不存在 - ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation “categories” does not exist ActiveRecord::StatementInvalid: PG::UndefinedTable: 错误: 关系“通道”不存在 - ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation “channels” does not exist ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: 关系表不存在) - ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation table does not exist) ActiveRecord :: StatementInvalid:PG :: UndefinedTable:错误:在Rails查询中 - ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: in rails query ActiveRecord :: StatementInvalid:PG :: UndefinedTable在多对多关系中但表存在 - ActiveRecord::StatementInvalid: PG::UndefinedTable in many to many relation but table exists ActiveRecord :: StatementInvalid(PG :: UndefinedTable:错误:关系“ spree_orders”不存在 - ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation “spree_orders” does not exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM