如何让“无论何时" gem 在 Windows 上工作? [英] How to make 'whenever' gem work on Windows?

查看:18
本文介绍了如何让“无论何时" gem 在 Windows 上工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Windows XP 上运行简单"的 cron.所以我安装了 gem installwhen 然后运行我的 cron.rb

I wan to run "simple" cron using whenever on Windows XP. So I installed whenever gem install whenever and then ran my cron.rb

require 'rubygems' 
require 'whenever' 
every 1.days, :at => '5:30am' do 
  command "puts now" 
end 

但它抱怨说

You don't have i18n installed in your application. 
Please add it to your Gemfile  and run bundle install

所以我运行了 gem install i18n,现在同样的代码给了我一个错误

So I ran gem install i18n and now the same code gives me an error

C:whenever>ruby cron.rb 
cron.rb:4: undefined method 'every' for main:Object (NoMethodError)

知道当 gem 工作时我可以如何制作吗?

Any idea how I can make whenever gem work?

  • ruby 1.8.7(2010-08-16 补丁级别 302)[i386-mingw32]
  • 宝石 1.3.7

本地宝石

aaronh-chronic (0.3.9)
activesupport (3.0.9)
backports (1.18.2)
daemons (1.1.0)
delayed_job (2.0.3)
eventmachine (0.12.10 x86-mswin32-60)
fastercsv (1.5.4)
haml (3.0.21)
i18n (0.6.0)
json (1.5.1)
mechanize (1.0.0)
monkey-lib (0.5.4)
nokogiri (1.5.0 x86-mingw32, 1.4.3.1 x86-mingw32)
rack (1.2.1)
rdiscount (1.6.8)
ruby-growl (3.0)
sinatra (1.2.6, 1.0)
sinatra-advanced-routes (0.5.1)
sinatra-reloader (0.5.0)
sinatra-sugar (0.5.1, 0.5.0)
thin (1.2.7 x86-mswin32)
tilt (1.3)
whenever (0.6.8)

推荐答案

这个 gem 是 *nix 实用程序 cron 的包装器.我们可以在 gem 源文件中看到 command_line.rb 第 75 行,它使用 'crontab' shell 命令.

This gem is a wrapper for the *nix utility cron. We can see in the gem source file command_line.rb line 75 that it uses 'crontab' shell command.

它不适用于标准 Windows 安装,因为此命令不可用.

It will not work on a standard Windows install as this command is not available.

有诸如 cronw 之类的 windows 版本,但我不能说这些是否与任何时候兼容宝石.

There are windows versions such as cronw, but I cannot say if these would be compatible with the whenever gem.

或者,您可以将长时间运行的任务作为 Windows 服务运行.这篇文章应该可以帮助您入门.

Alternatively you could run your long running task as a windows service. This article should get you started.

如果您必须使用when/cron,可能是因为您在*nix 上进行部署,请尝试下载Binami Rubystack VM - 您将在几分钟内启动并运行.

If you must use whenever/cron, perhaps because you are deploying on *nix, try downloading the Binami Rubystack VM - you'll be up and running in minutes.

这篇关于如何让“无论何时" gem 在 Windows 上工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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