PG :: UndefinedTable:错误:关系“服务”不存在第1行:选择“服务”。* FROM“服务”

时间:2017-09-25 08:32:17

标签: ruby-on-rails ruby postgresql cron whenever

我使用随时随地的宝石有些麻烦。我创建了一个rake任务,当我自己启动它时工作完全正常但是当我尝试使用我的日志中收到以下消息时自动化它:

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

这是一个命名问题吗?我检查并仔细检查,但我错过了什么?

我的环境是发展。

这是我的日程表.rb:

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

和我的架构:

class Service < ApplicationRecord
  has_many :pings, dependent: :destroy
  validates :name, uniqueness: true, presence: true
  validates :web_api, uniqueness: true, presence: true
end

这是我的模特: - service.rb

    public static void startServerAndLocator() throws InterruptedException {
    ServerLauncher serverLauncher = new ServerLauncher.Builder()
            .setMemberName("server1")
            .setServerPort(40404)
            .set("start-locator", "127.0.0.1[10334]")
            .build();

    ServerLauncher.ServerState state = serverLauncher.start();
    _logger.info(state.toString());

    Cache cache = new CacheFactory().create();
    createLuceneIndex(cache);
    cache.createRegionFactory(RegionShortcut.PARTITION).create("test");
}

public static void createLuceneIndex(Cache cache) throws InterruptedException {
    LuceneService luceneService = LuceneServiceProvider.get(cache);
    luceneService.createIndexFactory()
            .addField("fullName")
            .addField("salary")
            .addField("phone")
            .create("employees", "/test");
}
  • ping.rb

    class Ping&lt; ApplicationRecord   belongs_to:服务 端

1 个答案:

答案 0 :(得分:1)

所以我发现问题出在哪里,这要归功于你的意见。

Cron正在发送:

/bin/bash -l -c 'cd /Users/Naekh/code/yoando/statuschecker/statuschecker && RAILS_ENV=production bundle exec rake check:all --silent >> log/cron_log.log 2>> log/cron_error_log.log'

正如您所看到的,即使按照我的日程安排,他也会将其发送到生产环境:

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

我告诉他把它发送到开发环境。我现在需要找到一种方法来强迫他像我跑的那样进入那个环境:

/bin/bash -l -c 'cd /Users/Naekh/code/yoando/statuschecker/statuschecker && RAILS_ENV=environment bundle exec rake check:all --silent >> log/cron_log.log 2>> log/cron_error_log.log'

它有效

我用:

更新了cronjob环境
whenever --update-crontab --set environment='development'

现在它运作顺利