Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
521 views
in Technique[技术] by (71.8m points)

ruby - How to make 'whenever' gem work on Windows?

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 

but it complained that

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

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)

Any idea how I can make whenever gem work?

  • ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
  • gem 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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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

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

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...