[英]whenever gem not working, Rails 4
I am using Whenever gem to schedule some work on my site. 我正在使用everyever gem在我的网站上安排一些工作。 Currently I am working on development environment.
目前,我正在开发环境中。
I have instaled gem as guide suggests. 我已按照指导说明安装了宝石。
In schedule.rb 在schedule.rb中
every 2.minutes do
rake "vip_recomend:give"
end
In lib/tasks/ vip_recomend.rake 在lib / tasks / vip_recomend.rake中
namespace :vip_recomend do
desc "Give vip recomend to ads that are in waiting list"
task give: :environment do
girls = Girl.all
girls.each do |girl|
BlacklistMailer.blacklisted(girl).deliver
end
user = User.first
UserMailer.password_reset(user).deliver
end
end
Then I tried these comands: 然后我尝试了这些命令:
whenever --set environment=development --update-crontab
or 要么
whenever --update-crontab
Nothing happens. 什么都没发生。
Then I check if cron is updated with my stuff with this: 然后我检查cron是否用我的东西更新了:
crontab -l
Output: 输出:
# Begin Whenever generated tasks for: /home/my_host/blogs/config/schedule.rb
* * * * * /bin/bash -l -c 'cd /home/my_host/blogs && RAILS_ENV=development bundle exec rake vip_recomend:give --silent >> /log/cron_log.log 2>&1'
# End Whenever generated tasks for: /home/my_host/blogs/config/schedule.rb
When I try to run rake task from console it works. 当我尝试从控制台运行rake任务时,它可以工作。
Any help on this? 有什么帮助吗? Thanks.
谢谢。
Update 1 更新1
when in schedule.rb I have this 在schedule.rb中时,我有这个
env :PATH, ENV['PATH']
In cron error logs I get this message. 在cron错误日志中,我收到此消息。
/opt/alt/ruby21/lib64/ruby/2.1.0/rubygems/dependency.rb:298:in `to_specs': Could not find 'bundler' (>= 0) among 8 total gem(s) (Gem::LoadError)
from /opt/alt/ruby21/lib64/ruby/2.1.0/rubygems/dependency.rb:309:in `to_spec'
from /opt/alt/ruby21/lib64/ruby/2.1.0/rubygems/core_ext/kernel_gem.rb:53:in `gem'
from /home/individualki/rubyvenv/ror/2.1/bin/bundle:22:in `<main>'
Try writing your jobs in schedule.rb
in the following format, with a specified environment: 尝试在指定的环境下以以下格式在
schedule.rb
中写入作业:
every 2.minutes do
rake "vip_recomend:give", :environment => 'development'
end
Then go to your command prompt, and from within your application directory, try the following: 然后转到命令提示符,并从应用程序目录中尝试以下操作:
$ whenever --update-crontab
$ whenever
You should see that whenever lists your tasks with ENV=DEVELOPMENT
now. 您应该看到,无论何时使用
ENV=DEVELOPMENT
列出您的任务。
PATH problem may be, by putting the following at the top of the schedule.rb, ensure correct bundle path PATH问题可能是通过将以下内容放在schedule.rb的顶部来确保正确的分发包路径
env :PATH, ENV['PATH']
Or try to add following if above one not work. 或尝试添加以下内容(如果以上一项无效)。
env :GEM_PATH, ENV['GEM_PATH']
SOLUTION: 解:
I changed Whenever to Rufus-scheduler. 我将Everyever更改为Rufus-scheduler。
Before that I tried EVERY possible solution to fix my problem. 在此之前,我尝试了所有可能的解决方案来解决我的问题。 I think problem was in my Ruby installation on shared hosting, but I didn't have time to examine it.
我认为问题出在共享主机上的Ruby安装中,但是我没有时间检查它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.