无法测试cron工作使用无论gem在rails 3 [英] Not able to test cron job using whenever gem in rails 3

查看:230
本文介绍了无法测试cron工作使用无论gem在rails 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用runner而不是rake任务在rails 3中执行cron作业。



步骤1:
我每次安装gem并且scheduler.rb都有以下内容:

  set:environment,'development'
set:output,{
:error => /log/error.log,
:standard => /log/cron.log
}

every 1.minute do
runnerCron.sendAutomaticsSMS()
end



步骤2:



Cron档案: lib / cron.rb

  class Cron< ActiveRecord :: Base 

def ** sendAutomaticsSMS **()
----这里的一些代码---
end
end

步骤3:

 每当--update-crontab --set environment = development 

crontab文件。



步骤4:



  crontab -e 

它打开cron选项卡文件,其中包含要调用的cron作业方法的详细信息:






 #Begin每当生成的任务:store 

#结束每当生成的任务:store

#开始每当生成的任务:/ code / rails_projects / new / bhk / bigbhk- dev / config / schedule.rb
* * * * * / bin / bash -l -c'cd< * RAILS_APP_PROJECT_LOCATION *> &&&脚本/ rails runner -e开发'\''** Cron.sendAutomaticsSMS()**'\''> $

#End每当生成的任务:/ code / rails_projects / new /bhk/bigbhk-dev/config/schedule.rb






步骤5:



运行cron作业:

 code> $ sudo service cron restart 

cron停止/等待
cron启动/运行,进程4027

这不会做任何事情。我等待在sendAutomaticsSMS()方法中定义的操作,但是cron甚至不输入这个方法。



我没有在log / development.log中看到任何错误,我的rails应用程序中没有log / cron.log。

解决方案

我认为这是你的问题的症结: / bin / bash:/ log / cron .log:没有这样的文件或目录。在驱动器的根目录中没有 log 目录。尝试将日志路径更改为 /var/log/error.log /var/log/cron.log


I did the following to implement cron jobs in rails 3 using a "runner" instead of a rake task.

Step 1: I have whenever gem installed and scheduler.rb has following:

  set :environment, 'development'
  set :output, {
 :error    => "/log/error.log",
 :standard => "/log/cron.log" 
  }

  every 1.minute do
  runner "Cron.sendAutomaticsSMS()"
  end

Step 2:

Cron file: lib/cron.rb

    class Cron < ActiveRecord::Base

      def **sendAutomaticsSMS**()
         ----some code here ---
      end
    end

Step 3:

    whenever --update-crontab --set environment=development 

This updates crontab file.

Step 4:

Checked contents of crontab file using:

    crontab -e  

It opens cron tab file which has details of cron job method to be invoked:


    # Begin Whenever generated tasks for: store

    # End Whenever generated tasks for: store

    # Begin Whenever generated tasks for: /code/rails_projects/new/bhk/bigbhk-     dev/config/schedule.rb
    * * * * * /bin/bash -l -c 'cd <*RAILS_APP_PROJECT_LOCATION*> && script/rails runner -e development '\''**Cron.sendAutomaticsSMS()**'\'' >$

    # End Whenever generated tasks for: /code/rails_projects/new/bhk/bigbhk-dev/config/schedule.rb


Step 5:

Running cron job:

    $sudo service cron restart

    cron stop/waiting
    cron start/running, process 4027

This does not do anything. I wait for operation as defined in sendAutomaticsSMS() method to execute but the cron doesn't even enter this method.

I don't see any error in log/development.log and there is no log/cron.log in my rails app.

解决方案

I think this is the crux of your issue: /bin/bash: /log/cron.log: No such file or directory. There is no log directory at the root of the drive. Try changing your log paths to /var/log/error.log and /var/log/cron.log.

这篇关于无法测试cron工作使用无论gem在rails 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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