Cron工作不工作在Whenever gem [英] Cron job not working in Whenever gem

查看:85
本文介绍了Cron工作不工作在Whenever gem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一堆任务的应用程序,并且每天我想运行一个cron作业,为数据库中的每个任务创建一个DayTask。任务has_many DayTasks和这些daytasks是用户将每天检查。我使用任何gem,但它似乎并没有运行。任何想法?

I have an application that contains a bunch of tasks, and every day I want to run a cron job that creates a DayTask for each Task in the database. A Task has_many DayTasks and these daytasks are what users will be checking off every day. I'm using the whenever gem but it doesn't seem to be running at all. Any ideas?

config / schedule.rb

config/schedule.rb

every 1.day, :at => "12:01am" do
  runner "Task.generate_tasks_for_day"  
end

Task.rb

  def generate_tasks_for_day
    Task.all.each do |task|
      task.day_tasks.create(:target_date => Date.today)
    end 
  end 



result of running the 'whenever command'

1 0 * * * /bin/bash -l -c 'cd /home/grant/rails_projects/GoalTwist && script/rails runner -e production '\''Task.generate_tasks_for_day'\'''

注意:我每次在测试运行时都会改变config / schedule.rb中的时间。

Note: I've been changing the times in config/schedule.rb every time I want to test run it.

推荐答案

我已经解决了如何运行宝石Whenever。
它在生产中工作良好,但不是在开发模式下(我认为在开发模式下工作良好,你必须做一些技巧)。

Finally I have solved how to run the gem Whenever. It's working good on production, but not in development mode (I think that to working good in dev mode you must do some tricks).


  1. 安装宝石

  2. 写您的 scheduler.rb 文件

  3. 推送到远程服务器

  4. 登录到远程服务器$ c> ssh )

  5. 查看是否每次通过在终端上运行都上传:每当 li>
  6. 通过运行crontab时更新:每当--update-crontab

  7. 重新启动服务器crontab例如在Ubuntu服务器中): sudo服务cron重新启动

  8. 检查crontab是否在服务器上实现: crontab -l <​​/ code>

  1. install the gem
  2. write your scheduler.rb file
  3. push to the remote server
  4. login to the remote server (for example with ssh)
  5. see if whenever is good uploaded by running in terminal: whenever
  6. update whenever crontab by running: whenever --update-crontab
  7. restart the server crontab (for example in Ubuntu server): sudo service cron restart
  8. check if crontab is good implemented on the server: crontab -l

就是这样!


  1. 编辑crontab: crontab - e

  2. 附加我的cron每天在上午5:00 - 对于不基于Linux的服务器可能有点不同):

    0 5 * * * / bin / bash -l -c'cd / path_to_my_app / current&& RAILS_ENV = production bundle exec rake my_cron_rake'

  3. 检查是否良好实现: crontab -l <​​/ code>

  4. 完成

  1. Edit the crontab: crontab -e
  2. Append my cron (e.g. every day at 5:00 AM - can be little different for not-Linux-based server):
    0 5 * * * /bin/bash -l -c 'cd /path_to_my_app/current && RAILS_ENV=production bundle exec rake my_cron_rake'
  3. Check if good implemented: crontab -l
  4. Done

这篇关于Cron工作不工作在Whenever gem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆