2011-07-21 42 views
1

我希望在Windows XP上使用「簡單」cron。所以我安裝每當gem install whenever然後跑到我cron.rb如何讓'每當'寶石在Windows上工作?

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現在同樣的代碼給我一個錯誤

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

任何想法如何我可以讓寶石工作?

  • 紅寶石1.8.7(2010-08-16 PATCHLEVEL 302)[I386-的mingw32]
  • 寶石1.3.7

LOCAL GEMS

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) 
+0

謝謝@保羅。 – Radek

+0

我現在正在使用rufus gem http://rufus.rubyforge.org/rufus-scheduler/ – Radek

回答

5

此寶石是一個* nix實用程序包裝器cron。我們可以在第75行的寶石源文件command_line.rb中看到它使用'crontab'shell命令。

由於此命令不可用,它無法在標準的Windows安裝中使用。

有Windows版本,如cronw,但我不能說這些是否會與每當寶石兼容。

或者,您可以將長時間運行的任務作爲Windows服務運行。 This article should get you started.

如果您必須使用when/cron,可能是因爲您正在部署在* nix上,請嘗試下載Binami Rubystack VM - 您將在幾分鐘內啓動並運行。

+1

我不需要隨時使用。我的生產環境是Windows。所以我需要像cron for Windows那樣的紅寶石。我想這會是一個很好的新問題。感謝您的幫助。 – Radek