【问题标题】:cron jobs not working aws whenever gem rails每当 gem rails 时,cron 工作都无法正常工作
【发布时间】:2018-06-19 22:48:44
【问题描述】:

我知道这是一个非常常见的问题,但我觉得我需要一个具体的答案来帮助找出我哪里出错了......

每当 gem 加载以管理 cron 作业时 - 它在开发中运行良好,但是当我将应用程序加载到 AWS 时,我似乎无法正常工作...

当我通过 SSH 连接到实例时,我可以运行 crontab -l,它会列出无论何时执行的任务,但它似乎并没有真正执行它们。我也找不到任何日志文件来了解它为什么没有触发。

这是我从 eb 活动日志中提取的内容..

+++ GEM_ROOT=/opt/rubies/ruby-2.3.6/lib/ruby/gems/2.3.0
++ ((  0 != 0  ))
+ cd /var/app/current
+ su -c 'bundle exec whenever --update-cron'
[write] crontab file updated
+ su -c 'crontab -l'


# Begin Whenever generated tasks for: 
/var/app/current/config/schedule.rb at: 2018-01-10 06:08:24 +0000
0 * * * * /bin/bash -l -c 'cd /var/app/current && bundle exec 
bin/rails runner -e production '\''Trendi.home'\'' >> 
app/views/pages/cron.html.erb 2>&1'

# End Whenever generated tasks for: 
/var/app/current/config/schedule.rb at: 2018-01-10 06:08:24 +0000
[2018-01-10T06:08:24.705Z] INFO  [15603] - [Application update app-
a3a0-180109_230627@16/AppDeployStage1/AppDeployPostHook] : Completed 
activity. Result:
Successfully execute hooks in directory 
/opt/elasticbeanstalk/hooks/appdeploy/post.

这是我在 ebextensions 文件夹中的配置文件

files:
    "/opt/elasticbeanstalk/hooks/appdeploy/post/01_cron.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
       #!/usr/bin/env bash
       # Using similar syntax as the appdeploy pre hooks that is 
       managed by AWS
       set -xe

       EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container 
       -k script_dir)
       EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config container 
       -k support_dir)
       EB_DEPLOY_DIR=$(/opt/elasticbeanstalk/bin/get-config container 
       -k app_deploy_dir)

       . $EB_SUPPORT_DIR/envvars
       . $EB_SCRIPT_DIR/use-app-ruby.sh

       cd $EB_DEPLOY_DIR
       su -c "bundle exec whenever --update-cron"
       su -c "crontab -l"

我的日程安排.rb

      ENV['RAILS_ENV'] = "production"
      set :output, "app/views/pages/cron.html.erb"
      every 1.hour, at: ":00"do # 1.minute 1.day 1.week 1.month 1.year 
      is also supported
       runner "Trendi.home", :environment => 'production'
      end

我的任务存储在 /lib/

   module Trendi
    def self.home
     #exectuted task code here
    end

【问题讨论】:

    标签: ruby-on-rails amazon-web-services cron whenever


    【解决方案1】:

    您可以在您的 crontab 中尝试一个更简单的命令并将其更改为每分钟触发一次。例如。

    /bin/echo "test" >> /home/username/testcron.log

    这样您就可以快速排除是否是 cronjob 是罪魁祸首。请记住使用每个命令的完整路径。因此,在您的情况下,您可能希望更改“捆绑”命令以使用完整路径。您可以使用“which”命令找到路径。

    另外,你确定你正确地逃到这里了吗?

    -e 生产 '\''Trendi.home'\''

    这样不是更合适吗?

    -e 制作“Trendi.home”

    【讨论】:

    • 好吧,我不是直接写给 cron,因为我使用 gem 来处理它。有没有办法检查 aws 日志以查看 cron 是否正在触发?在我在 schedule.rb 中指定的 cron 日志之外
    猜你喜欢
    • 1970-01-01
    • 2013-11-12
    • 1970-01-01
    • 1970-01-01
    • 2013-10-20
    • 1970-01-01
    • 1970-01-01
    • 2015-02-28
    • 1970-01-01
    相关资源
    最近更新 更多