每当宝石红宝石

时间:2019-03-18 15:26:47

标签: ruby-on-rails cron rubygems

我创建了一个简单的任务,该任务通过控制器“何时”从控制器运行方法。

schedule.rb

set :environment, :development
env :PATH, ENV['PATH']
set :output, { :error => "log/error.log", :standard => 'log/cron.log' }

every 2.minutes do 
   runner "ParserController.test1"
end

parser_controller.rb:

def self.test1
    puts "HELLO PARSER"
end

每次执行--update-crontab并等待2分钟时,我都会在日志中出现错误:

bundler: not executable: bin/rails

更新:

我尝试在不使用cron的情况下运行命令,并得到2个不同的结果:

第一个变体是

bundle exec bin/rails runner -e development 'ParserController.test1'

'bundler: not executable: bin/rails'

第二个变种是

 bundle exec rails runner -e development 'ParserController.test1'

HELLO PARSER

1 个答案:

答案 0 :(得分:0)

尝试添加env :GEM_PATH, ENV['GEM_PATH']

schedule.rb

set :environment, :development
env :PATH, ENV['PATH']
env :GEM_PATH, ENV['GEM_PATH']
set :output, { :error => "log/error.log", :standard => 'log/cron.log' }

every 2.minutes do 
   runner "ParserController.test1"
end