帮助“每当” Ruby 中用于 cron 任务的 gem

发布于 2024-09-27 00:57:11 字数 1056 浏览 5 评论 0原文

我以前没有使用过 cron,所以我不能确定我这样做是否正确。我想要自动化的任务似乎没有运行。我在终端中执行了以下步骤:

  1. sudo gem install每当
  2. 更改到应用程序目录
  3. 每当。 (这创建了文件schedule.rb)
  4. 我将此代码添加到schedule.rb:

    每 10 分钟一次
      跑步者“User.vote”,环境=> “发展”
    结尾
    
    
    每小时做一次
      跑步者“Digest.rss”,:环境=> “发展”
    结尾
    
  5. 我将此代码添加到deploy.rb:

    在“deploy:symlink”、“deploy:update_crontab”之后
    
    
    命名空间:部署做
      desc“更新 crontab 文件”
      任务:update_crontab,:角色=> :db 做
        运行“cd #{current_path} && 每当 --update-crontab #{application}”
      结尾
    结尾
    
  6. 我在终端中执行了此操作:每当

  7. 它返回:

    @hourly cd /Users/RedApple/S && script/runner -e 开发 'Digest.rss'
    
    
    0,10,20,30,40,50 * * * * cd /Users/RedApple/S && script/runner -edevelopment 'User.vote'
    
  8. 在终端中单独运行这些命令:

    script/runner -edevelopment 'Digest.rss'
    script/runner -edevelopment 'User.vote'
    
  9. 现在在开发模式(脚本/服务器)下运行本地服务器,我没有看到任何证据表明代码实际上正在运行。是不是有什么步骤我没做?除了我所做的之外,没有“每当”的指南显示任何其他内容。

I have not used cron before, so I can't be sure that I did this right. The tasks I want to be automated don't seem to be running. I did these steps in the terminal:

  1. sudo gem install whenever
  2. change to the application directory
  3. wheneverize . (this created the file schedule.rb)
  4. I added this code to schedule.rb:

    every 10.minutes do
      runner "User.vote", environment => "development"
    end
    
    
    every :hour do
      runner "Digest.rss", :environment => "development"
    end
    
  5. I added this code to deploy.rb:

    after "deploy:symlink", "deploy:update_crontab"
    
    
    namespace :deploy do
      desc "Update the crontab file"
      task :update_crontab, :roles => :db do
        run "cd #{current_path} && whenever --update-crontab #{application}"
      end
    end
    
  6. I did this in the terminal: whenever

  7. It returned:

    @hourly cd /Users/RedApple/S && script/runner -e development 'Digest.rss'
    
    
    0,10,20,30,40,50 * * * * cd /Users/RedApple/S && script/runner -e development 'User.vote'
    
  8. Running these commands individually in the terminal works:

    script/runner -e development 'Digest.rss'
    script/runner -e development 'User.vote'
    
  9. Now running a local server in development mode, script/server, I don't see any evidence that the code is actually being run. Is there some step that I didn't do? No guides for "Whenever" show anything else than what I have done.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

厌倦 2024-10-04 00:57:11

我对任何时候都很陌生,但我认为运行只是

whenever

向您展示了创建的 cron 作业的样子。为了实际编写 cron 作业(使其处于活动状态),您需要执行:

whenever -w

这将为您提供完整的选项列表:

whenever -h

I'm new to whenever as well, but i think that just running

whenever

just shows you what the cron job that is created will look like. In order to actually write the cron job (to make it active), you need to execute:

whenever -w

This will get you a full list of options:

whenever -h
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文