Every repository with this icon (
Every repository with this icon (
| Description: | Provides clean ruby syntax for defining messy cron jobs and running them Whenever. edit |
-
Hello,
I have a Rails project where I'm using Capistrano for deployment tasks. I need to configure some recurring events with crontab and I decided to try whenever.
Unfortunately, as soon as I include the gem in the Rails environment, Capistrano no longer works.Here's the error
$ cap deploy:check /Users/weppos/.rvm/gems/ruby/1.8.7/gems/capistrano-2.5.9/lib/capistrano/configuration/namespaces.rb:97:in `task': defining a task named `symlink' would shadow an existing method with that name (ArgumentError)Here's my environment.
Rails 2.3.5 Capistrano 2.5.9 Whenever 0.4.1 (as Gem)I investigated the issue and I found the problem. In the
whenever.rbfile you load the projectRakefile.# Hoping to load Rails' Rakefile begin load 'Rakefile' rescue LoadError nil endThe
Rakefilerequiresrakewhich inject the FileUtils into the current Ruby scope. FileUtils provide aObject#symlinkmethod which goes in conflict with Capistrano. Here's the original source.Now the question is: why do you need to load the
Rakefilein thewhenever.rbfile? It only seems to contain tasks focused on packaging and releasing the Gem. It also includes theversion.rbfile, but you can easily copy the statement inwhenever.rb.In this way, you will make your library compatible with Capistrano.
Comments
-
should support both active_support and activesupport
1 comment Created 28 days ago by daeltar -
set environment=development does not work
4 comments Created about 1 month ago by tamoyalMacintosh-2:mls TAmoyal$ whenever --update-crontab appname --set environment=development --load-file ./config/development/schedule.rb
[write] crontab file updated Macintosh-2:mls TAmoyal$ whenever
PATH=/usr/bin:/bin:$PATH
0 4 * cd /Users/TAmoyal/Desktop/RoR_Projects/mls && RAILS_ENV=production /usr/bin/env rake thinking_sphinx:index >> /Users/TAmoyal/Desktop/RoR_Projects/mls/log/cron.log 2>&1Comments
When you run 'whenever' with no options like that it doesn't show you your actual crontab file, but rather your schedule.rb converted to cron syntax.
Run 'crontab -l' to see your crontab file.
ah yea....keep forgetting that. sorry! have you experienced any issues with a cron task being invoked more than once at the same time? I am pretty good about logging for my tasks and I have the following in my log:
[2009-11-19 08:00:14] [Info] Starting send_daily_activity_email task... [2009-11-19 08:00:14] [Info] Starting send_daily_activity_email task... [2009-11-19 08:00:15] [Info] Sent a daily activity email to 'corgan1003@gmail.com' [2009-11-19 08:00:15] [Info] Sent a daily activity email to 'corgan1003@gmail.com' [2009-11-19 08:00:15] [Info] Finished send_daily_activity_email task. [2009-11-19 08:00:15] [Info] Finished send_daily_activity_email task.
As you can see, my task was run twice at the same time but my crontab is definitely not saying to do this:
0 8 * cd /Users/TAmoyal/Desktop/RoR_Projects/mls && RAILS_ENV=development /usr/bin/env rake util:send_daily_activity_email >> /Users/TAmoyal/Desktop/RoR_Projects/mls/log/cron.log 2>&1I should add some output to the plain whenever command..
I've never seen a job run twice like that. I would check your whole crontab file to make sure there's not a duplicate entry in there and also that there's not a duplicate record in the database for that user.
well the task is invoked twice so it would have nothing to do with duplicate database entries (however there are not duplicates). i also checked my crontab file. anyway, since whenever just writes to cron this is obviously not a whenever bug so i'll close the issue. thanks for the comments
-
Conditional task execution depending on environment
4 comments Created about 1 month ago by klmI can't get crontab to update conditionally using Capistrano. I've got a few jobs that I only want to run in a production environment (emails, etc). Given a deploy.rb snippet:
run "cd #{release_path} && whenever --update-crontab #{application} --set environment=#{stage}"
and a schedule.rb snippet:
if @environment == 'production'
every 2.hours dorake 'some_task'end end
similarly, I've tried:
if Rails.env.production?
every 2.hours dorake 'some_task'end end
I cannot get schedule.rb to recognize @environment. If I run whenever from the command line, e.g. 'whenever --set environment=some_env', then 'some_env' is properly added to the generated rake task as RAILS_ENV=some_env.
By the way, anything outside of a conditional is added to the crontab. Any idea what I'm doing wrong?
Comments
I realized I might not have been clear enough:
If I use whenever from the command line, everything is generated properly, with the correct environment specified for any tasks.
If I use whenever via capistrano, any jobs outside of a conditional are added to the crontab. Those jobs have the right environment set.
If I try to write a job conditionally, using @environment or Rails.env, nothing inside the conditional is written to the crontab when I use capistrano, e.g. 'cap staging deploy' or 'cap production deploy'.
Sorry for not getting back to you sooner. So you've resolved this issue?
-
every 1.day, :at => "6:30" # Supposed to local time
but as it don't work, i have to do something like:
every 1.day, :at => "#{Time.zone.parse('6:30').getlocal.hour}:30"
Comments
The current one, that not depend of ActiveSupport is:
every 1.day, :at => "#{Time.parse('6:30 A').getlocal.strftime("%H:%M")}" do
-
It looks like pallan's fork supports this already (http://github.com/pallan/whenever). It would be nice to get it into the main repo and gem.
Comments
-
How can I load different schedule.rb files for different environments?
6 comments Created 2 months ago by tamoyalI am a bit confused about how to load different schedule.rb files for different environments. I would think there would be a way to specify the schedule.rb location in the "whenever --update-crontab..." command but that does not seem to be the case (or i can't find it). Could you provide an example of how to do this? Thanks!
Comments
I should mention that "--load-file=file_path" does not work for me
The correct usage is "--load-file file_path" (drop the "=")
With that, in combination with detecting your environment in your cap file and separate schedule files for each environment (perhaps schedule_production.rb, schedule_staging.rb, etc) you should be able to accomplish this.
I actually tried that but now I see the issue. I was checking the results of the command bu doing whenever which probably defaults back to config/schedule.rb. Now when I check it with crontab -l, it actually gives me the cron jobs and I see that --load-file PATH did work properly. I was confused and thought whenever looked at the system cron
Just update your schedule.rb file with:
if Rails.env.development?
stuff else
other stuff end@retr0h I prefer to keep these things in separate files
-
Please host the gem on either RubyForge or (preferably) GemCutter
3 comments Created 2 months ago by dallasSince GitHub's move to RackSpace, gems.github.com is down and there is not ETA as to when (or even if) it will be back. They suggest using GemCutter.
Comments
-
Comments
Is there anything you suggest I fix? This sounds like a clash with Rake, which Whenever uses, but not a problem with Whenever directly.
-
Is it possible (desirable) to add a hour range to tasks like the one I did (just an experiment with the code, therein no tests) here: http://github.com/lucashungaro/whenever/commit/5d97d5150882263a55a2e8789b6dff68541468b1 ?
With that I can configure a task like the following:
every 5.minutes, :hour_range => "1-23" do
command "do_something" endAnd get the following cron config:
0,5,10,15,20,25,30,35,40,45,50,55 1-23 * do_somethingComments
-
I'm using whenever to create a cron job that calls a model method that sends some emails. The problem is - the emails are not getting sent. There are no cron errors.
I checked in syslog and just to be sure I set up cron.log.
http://www.casualcode.com/2008/05/18/how-to-enable-cron-log-in-ubuntu/
No errors recorded.
The method appears to run. In my production log, I see the a log.warn that I raised to show that the job ran - and it says an email was sent - but it is not.
If I run it manually - the emails are sent (IE script/runner 'Myclass.method').
I also tried flushing to Rails.logger.flush - hoping to see the google echo of the email being sent (that I see when ran manually) but no go :(
The same thing happens when I move to a rake task - rather than script/runner.
I'm using action_mailer_optional_tls and google to send the emails. It does not seem to fail - it just does not send.
This prob is not a whenever or cron thing but thought I'd ask here, just in case :) Thank you.
Example log.
Sep 1 17:29:01 integrated /USR/SBIN/CRON[8003]: (deploy) CMD (/home/deploy/apps/pet/releases/20090901113413/script/runner -e production 'Plog.send_reminders;Rails.logger.flush')
Comments
Does the Ubuntu cron log capture stderr as well as stdout? If not, you could try my fyi gem which captures everything and logs it for you.
90% of mysterious cron problems come down to the fact that cron runs with a different path. To find out what path it's using, set up a cron job that echoes the path to standard out and inspect your Ubuntu / fyi log. Is it the same as the path you have when running your email job manually?
I'm not sure that it does but I set up fyi (thanks for that!) and here is what the output looks like ...
INFO -- : command: /home/deploy/apps/pet/releases/20090901113413/script/runner -e production 'Plog.send_reminders' duration: 7.232412s
status: SUCCESS
stdout:
stderr:When I echo my path from cron ...
[2009-09-02T14:21:01.714779 #8617] INFO -- : command: echo /usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games duration: 0.008s
status: SUCCESS
stdout: /usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
stderr:Which is the same that whenever pushes into there with --update-crontab
integrated ~: echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games integrated ~: which ruby
/usr/bin/rubyLooks like my path is ok - to be sure I used /usr/bin/ruby /home/deploy/apps/pet/releases/20090901113413/script/runner
Bummer, no biggy tho, thanks for your help!
Ok, well we can cross the path off the list of suspects.
Are you sure that the emails would be written out in production? I'm not certain but I think that ActionMailer logs email contents in development (and maybe test) but not production.
Anyway, the fact that send_reminders took 7 seconds suggests something is happening. I'm not sure why it's not working though!
Want to know something weirdererer? This one works - sends the emails and everything.
5 15 * fyi '/home/deploy/apps/pet/current/script/runner -e production "Plog.send_reminders"'
This one does not send the emails - but it does run without error - and creates a log etc. Funky. Stick a fork in me i'm stumped.
5 15 * /home/deploy/apps/pet/current/script/runner -e production "Plog.send_reminders"
I'm just going to take out
after "deploy:symlink", "deploy:update_crontab"And use current (rather than the release) and keep the same crontab. ha :)
-
Multiple environments overwrites crontab to last
3 comments Created 3 months ago by coreymartellaSeems that whenever overwrites the crontab if you have the same app running on multiple environments. We have production and staging on the same machine and want the crontab for both envs to be setup. But it seems the last --write-crontab overwrites the first.
[root@peitho /sites/capps/production/current]# whenever --write-crontab capps_production --set environment=production [write] crontab file written [root@peitho /sites/capps/production/current]# crontab -l
Begin Whenever generated tasks for: /usr/home/web/sites/capps/production/releases/20090828153640/config/schedule.rb
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/home/corey/bin:/home/corey/bin
20 0 * cd /usr/home/web/sites/capps/production/releases/20090828153640 && RAILS_ENV=production /usr/bin/env rake cron:daily_phase2 >> /usr/home/web/sites/capps/production/releases/20090828153640/log/cron_log.log 2>&1
30 23 * cd /usr/home/web/sites/capps/production/releases/20090828153640 && RAILS_ENV=production /usr/bin/env rake cron:daily_phase1 >> /usr/home/web/sites/capps/production/releases/20090828153640/log/cron_log.log 2>&1
0 cd /usr/home/web/sites/capps/production/releases/20090828153640 && RAILS_ENV=production /usr/bin/env rake cron:hourly >> /usr/home/web/sites/capps/production/releases/20090828153640/log/cron_log.log 2>&1
0,15,30,45 cd /usr/home/web/sites/capps/production/releases/20090828153640 && RAILS_ENV=production /usr/bin/env rake cron:pull_from_spokes >> /usr/home/web/sites/capps/production/releases/20090828153640/log/cron_log.log 2>&1
End Whenever generated tasks for: /usr/home/web/sites/capps/production/releases/20090828153640/config/schedule.rb
[root@peitho /sites/capps/production/current]# cd ../../staging/current [root@peitho /sites/capps/staging/current]# whenever --write-crontab capps_staging --set environment=staging
[write] crontab file written [root@peitho /sites/capps/staging/current]# crontab -lBegin Whenever generated tasks for: /usr/home/web/sites/capps/staging/releases/20090828150624/config/schedule.rb
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/home/corey/bin:/home/corey/bin
20 0 * cd /usr/home/web/sites/capps/staging/releases/20090828150624 && RAILS_ENV=staging /usr/bin/env rake cron:daily_phase2 >> /usr/home/web/sites/capps/staging/releases/20090828150624/log/cron_log.log 2>&1
30 23 * cd /usr/home/web/sites/capps/staging/releases/20090828150624 && RAILS_ENV=staging /usr/bin/env rake cron:daily_phase1 >> /usr/home/web/sites/capps/staging/releases/20090828150624/log/cron_log.log 2>&1
0 cd /usr/home/web/sites/capps/staging/releases/20090828150624 && RAILS_ENV=staging /usr/bin/env rake cron:hourly >> /usr/home/web/sites/capps/staging/releases/20090828150624/log/cron_log.log 2>&1
0,15,30,45 cd /usr/home/web/sites/capps/staging/releases/20090828150624 && RAILS_ENV=staging /usr/bin/env rake cron:pull_from_spokes >> /usr/home/web/sites/capps/staging/releases/20090828150624/log/cron_log.log 2>&1
End Whenever generated tasks for: /usr/home/web/sites/capps/staging/releases/20090828150624/config/schedule.rb
Comments
The --write-crontab option will always completely overwrite the crontab file. Try using the --update-crontab option. You might want to clear out your crontab file first as the update option will leave those existing entries alone.
coreymartella
Fri Aug 28 10:10:25 -0700 2009
| link
Apologies. The first capistrano blog post was what I stumbled upon and I see now the README shows the proper argument. Sorry again.....
-
Hi,
Using :
every 1.month, :at => '4:00 am' do
--do somethingend
produces in the crontab:
0 4 5So the correct hour, but not the correct month value.... As it should be expecting 0 4 1.
Cheers,
Tom
Comments
Hey Tom, the 1.month jobs are a little tricky. Unless you specify a day, Whenever (which uses Chronic to parse times) will assume you mean today which is why you're getting a 5 instead of a 1.
The best solution is to do:
every 1.month, :at => 'beginning of the month at 4am'This issue covers the same thing:
http://github.com/javan/whenever/issues/closed#issue/13 -
Smart-grouping code dying on mixed hourly/daily tasks
3 comments Created 4 months ago by tithoniumI've got an every :hour and an every :day task in my schedule, and I get this error:
/Library/Ruby/Gems/1.8/gems/javan-whenever-0.3.6/lib/job_list.rb:119:in `+': can't convert nil into Array (TypeError)It happens whenever I have a mix of hourly and non-hourly tasks, and is happening when job_list.rb#combine is processing the @hourly entry, where entries[i] is ['@hourly', '...whatever...'], and f == 2
Doesn't happen in 0.3.1, happens in 0.3.6.
Example schedule that triggers it:
every :hour do command "ls" end every 1.day, :at => "5:00am" do command "ls" endComments
Thanks! I believe this is a problem with the shortcuts like :hourly, :daily. As a temporary workaround, try using "every 1.hour" instead.
"every 1.hour" works. I'll use that for now, thanks.
-
Every block should execute commands as one big command by default
4 comments Created 5 months ago by daeltarReason behind this naturally assuming that task defined in one every block will run in specified order and not all at once.
For parallel execution should be used just multiple every blocks.
Comments
I'd gladly accept a patch for this! But seeing as Whenever has been around for a while and currently does not run jobs sequentially, I don't think that should become the default behavior. How about a syntax like:
every 1.day, :at => '3pm' do
sequential do command "one" command "two" end command "three" command "four"end
Where "one" and "two" will run sequentially and "three" and "four" will run in parallel.
I propose following DSL:
every 1.day, :at => '3pm', : sequential => true do
...end
that's fine with me, as long as sequential defaults to false
-
whenever updates crontab with no newline before EOL/EOF
6 comments Created 5 months ago by belliappaI am experiencing an issue where the closing identifier ("# End Whenever generated tasks for: /path/to/cron/schedule.rb") that is wrapped around the crontask does not have a newline at the end. As a result the cron jobs are not run on the server since Crontab requires there be a newline at EOL/EOF.
Version of Linux I am running into this error on: CentOS release 5.3
Link to a similar experience with crontab: https://bugs.launchpad.net/ubuntu/+source/cron/+bug/118168/+viewstatusNot sure if anyone has experienced this issue. I would appreciate any help on this issue.
Note: Doing a crontab -e on the server and then saving the file automatically adds the newline to the crontab file.
Comments
Thanks for this report. I'm going to push a new version out soon and I'll be sure to add a newline to the end of the output.
I had this issue as well, which led to me bypassing whenever. I'd definitely like to see this fixed as having source-controlled crontrab generation is ideal for me.
Adds new line after closing Whenever comment. Prevents accumulation of new lines with each --update-crontab. Closed by 434423f
This should be fixed now with the release of version 0.3.5. Could someone who was having trouble before try again and report back?
Was able to verify that your fix works. Much appreciate the quick turn around. Thank you.
-
Changing environments with whenever (--set is not working)
1 comment Created 5 months ago by tamoyalI have a task like the following:
every 1.day, :at => '4am' do
command "cd #{RAILS_ROOT} && rake thinking_sphinx:stop RAILS_ENV=#{RAILS_ENV}"
command "cd #{RAILS_ROOT} && rake thinking_sphinx:index RAILS_ENV=#{RAILS_ENV}"
command "cd #{RAILS_ROOT} && rake thinking_sphinx:start RAILS_ENV=#{RAILS_ENV}"
end
The problem is that even when I deploy, my cron tasks have RAILS_ENV=development in them.
I tried putting "whenever --set environment=production" in my deploy file but it doesn't help. I am actually not 100% sure what this does as I haven't found any good documentation on it. Any help would be great. My tasks are pretty much the same on development and production, but I need to tell thinking_sphinx which environment it is operating in.
Thanks!Comments
There is a rake helper that is designed for these type of tasks. Try:
every 1.day, :at => '4am' do rake "thinking_sphinx:stop" endThe rake helper automatically cd's into your app and sets the environment, but will use the environment you have set in your schedule.rb (defaults to production) and will respect anything you pass in using the --set option.
-
First of all, I want to thank Javan...his gem has definitely made a few things easier.
I found the following error when running script/console or the dev environment and typing in "Task.new" (Task is a model in my app)
WARNING: Deprecated reference to top-level constant 'Task'Tracing it out some more, it become obvious that my app had Task defined and Rake had Task defined. Hmmm...thats not good. So I started commenting out the various different things in config/environment.rb. Commenting out "require 'whenever'" stopped rake from loading in my dev environment (just as I would expect). This stopped the error.
Since I use "script/runner" with the whenever library, I ran "whenever" from the command line and it produced the desired results. This is the same command that capistrano deploy uses to update my crontab in my production environment.
From my testing, I dont think I need the "require 'whenever'" in my environment file, but maybe someone here can pitch in? Could someone also pitch in as to why we need to include Rake in the whenever library?
Thank you in advance for your feedback.
Comments
Hi there, I required 'rake' in the Whenever gem after following the Railscast on creating a gem. http://railscasts.com/episodes/135-making-a-gem I'm not confident that it needs to be there, and I will experiment with removing it.
I can confirm that it is causing a problem if you require 'whenever' in a rails app that has a Task model. However, if you require thethe gem using the config.gem syntax you won't have this problem because it doesn't load the actual lib, just requires its presence.
# environment.rb config.gem 'javan-whenever', :lib => false, :source => "http://gems.github.com"Finally, no, you don't need to require the whenever gem in your app. Just make sure the gem is installed on your production server or else you won't be able to deploy your schedule.
javan...thank you for all the work and looking into it.
Thank you for confirming that removing the line out of the environment file wouldnt be a problem. My production servers have the gem installed so that shouldnt be a problem.
Once again, thank you for all your hard work.
-
For some reason, every time
wheneveradds to our crontab, this comment gets appended to the top:# DO NOT EDIT THIS FILE - edit the master and reinstall. # (/tmp/crontab.XXXXf6xl04 installed on Thu Jun 25 21:01:10 2009) # (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)
Every time we deploy, another one of these appears at the top of the crontab.
Comments
Those comments definitely weren't written by Whenever. Whenever calls the unix command
crontabto actually write the crontab file so perhaps it is to blame. If you find that there's a way to avoid this with the crontab command, let me know.What OS are you running?
-
whenever command can't find my Rails gem version
3 comments Created 6 months ago by fadhlirahimI have multiple rails version in my machine and whenever can't generate the crontab. It keeps displaying the following:
Missing the Rails 2.2.2 gem. Please
gem install -v=2.2.2 rails, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.I have Rails 2.3.2 and Rails2.2.2 on the same machine. Although I could make whenever command work if I comment out the rails version but it is not a permanent solution because I need both rails gem in my machine.
Can you point out in your code where does this behavior happens?
Comments
Sounds similar to http://github.com/javan/whenever/issues#issue/1
The workaround, for now, is to uninstall the version of Rails that you're not using.
The problem is in lib/whenever.rb, it needs to check of there's a RAILS_GEM_VERSION defined before requiring 'activesupport'. I should have this fixed soon, but I'd welcome a patch if you feel like doing it.
Version 0.3.1 was just released. Hopefully it fixes your issue.
eivindhagen
Mon Nov 30 00:48:40 -0800 2009
| link
I'm having this same problem, but with more recent gem versions:
rails 2.3.3
whenever 0.4.0I also have rails 2.3.4 and 2.3.5 installed (along with many other versions).
The interesting thing is that the 'whenever' command works fine in my win32 dev system, but fails to operate on my hosting server (Linux). I get the follow error:Missing the Rails 2.3.3 gem. Please
gem install -v=2.3.3 rails, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.
-
When i tried to set a time with a monthly cronjob i had to use '1.month'.
But this created a cronjob for every month on todays day, eg.0 9 18 ..... instead of
0 9 1 ..... which would fire on the first day of the month...Comments
are you showing all of the cron output there? your first example has a 9 in the hour place and 18 in the day.
# .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * command to be executed
can you paste your schedule.rb file? something seems off.
Ah, I see the problem (other than me not having good docs in this area). When you use :at with 1.month, the day, hour, and minute get parsed from the time. So when you just use a time like 9am, it assumes the day you mean is today.
One way to correct this is give it a full date. I admit that this looks ugly, but it should work: every 1.month, :at => "January 1st 9am"
It will ignore the "January", but it's necessary for a successful parse (Whenever uses the Chronic gem for parsing dates and times).
Hope that helps.
the
If you dont want to give the full date, you could try something like this:
every 1.month, :at => "start of the month at 9am"
This will produce the intended "0 9 1 ". It will also keep your code a little cleaner :)Hope that helps.
-AP
Thanks Javan.
As you said, thats not good looking but it works!
tsommer...the above solution I posted should work. I'm not sure if you looked at it.
-
Capistrano says crontab written, but crontab -l doesn’t indicate that it was
1 comment Created 6 months ago by gordonbisnorI’ve been trying to get whenever running on an ec2 instance that was created with ec2 on rails, when I deploy with Capistrano it indicates that the crontab was written, but when I log into the server and run crontab -l it does not seem to have been changed. If I go into the release folder and manually run whenever --write-crontab then run crontab -l - it gets updated properly. Any ideas what could be causing this? Capistrano is not indicating any errors so not sure how to debug.
Comments
-
Whenever just isn't working for me...here is what i have done
12 comments Created 6 months ago by tamoyal-install the gem ( and add dependency to initializer as well as require 'whenever' to environment.rb)
-wheneverize .
-added cron jobs to the schedule.rb file
-run "whenever --update-crontab myappname"
When I run "whenever", i get valid cron jobs:
0,10,20,30,40,50 rake util:update_band_shows >> log/cron.log 2>&1
for example
....that rake is never called. there is also nothing in cron.log or the custom log i use for that task
any ideas? i am on mac os xComments
Is whenever supposed to update my /etc/crontab? There are no cron jobs in there but somehow running "whenever" still shows valid cron jobs
Running 'whenever' simply converts your schedule.rb file into cron syntax and outputs it, running 'crontab -l' will list the actual installed cron jobs on your system.
If you paste your schedule.rb file, I might be able to assist your further.
crontab -l definitely shows the tasks.
# Begin Whenever generated tasks for: appname
0,10,20,30,40,50 rake util:update_band_shows >> log/cron.log 2>&1
my schedule.rb is:
set :cron_log, "log/cron.log"
every 10.minutes do
command "rake util:update_band_shows"
end
# reindex sphinx every 2 days
every 2.days, :at => '8am' do
rake "thinking_sphinx:stop RAILS_ENV=production"
rake "thinking_sphinx:index RAILS_ENV=production"
rake "thinking_sphinx:start RAILS_ENV=production"
end
Why the command for the first rake task and then rake for the following (sphinx) tasks? A couple other things. Cron needs full paths to execute tasks (and for the logs). So your first command might work if it was formatted something like: command "cd /path/to/my/app && util:update_band_shows"
And the path to the log should be absolute too.
Sorry, that was supposed to be: command "cd /path/to/my/app && rake util:update_band_shows"
i just realized that the "rake" command makes the cron change to the rails_root directory. i am testing that out again
even though the "rake" command was telling the cron to cd to my app path, I still got "env: rake: No such file or directory". then i tried doing command "cd #{RAILS_ROOT} && rake util:update_band_shows" and i got /bin/sh: line 1: rake: command not found. the rake works fine when i run it manually. do you know what the issue could be?
It sounds like cron doesn't know where rake is. Try setting a PATH in your schedule.rb file. For me, rake is in /opt/local/bin/, so I might do something like this:
env :PATH, "/opt/local/bin/rake:$PATH"
although you may need to add more paths than just that one.
ehutzelman
Mon Jun 22 22:29:52 -0700 2009
| link
This was my problem as well, setting the path with rake fixed it.
thanks, this also fixed my problem. do you have a different schedule.rb for each environment? it would make sense to have a different rake location and different tasks for each environment. how do you handle this?
My staging and production environment are almost identical so I don't have a need for separate files, but you can use the --load-file option to load a file other than schedule.rb so that might suit you.
-
At least in hostingrails.com rake cron jobs wont run cause "rake" command needs to be run with full path /usr/bin/rake, It would be nice to add a conf like :rake_path to be appended.
Comments
I have run into the same problem. I am trying this instead right now:
every 10.minutes do
command "rake util:update_myspace_shows" endYeah I did the same, change it to a command instead of rake runner
You might also try adding '/usr/bin' to your PATH in your schedule.rb file. Something like:
env :PATH, '/usr/bin:$PATH'
Although you may need to add more paths than just the one.
-
Here is the task:
every :day, :at => '9am' do
rake "util:blah" endHere is the error:
/usr/local/lib/ruby/gems/1.8/gems/javan-whenever-0.3.0/lib/outputs/cron.rb:41:in `>': comparison of Time with 0 failed (ArgumentError)Comments
-
I just starting using this great Gem and got into problems when specifying a specific day of week, like "every :sunday". Here is the output I get:
45 3 sun /home/.....
crontab: error on previous line; unexpected character found in line.
crontab: errors detected in input, no crontab file generated.I'm deploying to a Solaris server and it seems that Solaris does not accept the "sun" format for day of week. Is there a way to get whenever to use numbers instead?
Comments
Thanks for pointing this out. I can't give this issue much priority at this time, but I'll gladly accept a merge a pull request if you want to take a stab at it.
I have sent you a pull request for a change to use 0-6 instead of sun-sat for weekday.
Thanks! I just took a quick glance it all looks perfect. I'm get this merged in soon -- probably this weekend.
-
Hi,
I had some trouble when I've try to vendorize this gem into my app. Everything works fine untill I try to deploy my app on a server which don't have this gem installed but normaly, it has to use the vendorised version...
I think the problem is around the executable and the dependencies load... I've patched my version to load correctly dependencies from /vendor/gems/ and so it works now...
NB: The two executables are not into our PATH, so we have to lunch it manualy from RAILS_APP/vendor/gems/javan-whenever-0.2.2/bin/
To bypass this, I've copy the whenever script into my script/ directory :)
However, thanks for this great gem :)
Comments
Thanks, that's a pretty good solution. You could also modify your capistrano task to include the full path to whenever. Something like:
run "cd #{release_path} && /#{RAILS_ROOT}/vendor/gems/javan-whenever-0.2.2/bin/whenever --update-crontab #{application}"
-
I'm using this on my staging server but when I run whenever --update-crontab my_app all the created cron entries are for production. It would be great if you could specify which RAILS_ENV to set in the crontab and have that also work with capistrano.
Comments
Do you mean specify the environment when running the
whenevercommand or in your schedule.rb file? In your schedule.rb file you can: set :environment, :stagingAnd someone has created somewhat of a hack to automatically detect your environment that may or may not work for you: http://wiki.github.com/javan/whenever/automatically-detecting-environment
I just published a new version of the gem (0.3.0) that allows you to set variables, including the environment, on the fly:
http://wiki.github.com/javan/whenever/setting-variables-on-the-fly
-
I've just installed javan-whenever-0.2.2 and when I try to run wheneverize on my Rails 2.3.2 app I'm told that the wheneverize command is not found.
Comments
Try installing the gem with sudo:
sudo gem install javan-whenever
or
sudo rake gems:install
jeffleeismyhero
Mon Jun 01 07:07:14 -0700 2009
| link
I've done that.
config.gem "chronic" config.gem 'javan-whenever', :lib => false, :source => 'http://gems.github.com'The dependencies were installed and then whenever was installed.
[jlee@casweb5 mehmry]$ gem list --local *** LOCAL GEMS *** actionmailer (2.3.2, 2.2.2) actionpack (2.3.2, 2.2.2) activerecord (2.3.2, 2.2.2) activeresource (2.3.2, 2.2.2) activesupport (2.3.2, 2.2.2) authlogic (2.0.13) be9-acl9 (0.10.0) calendar_date_select (1.15) cgi_multipart_eof_fix (2.5.0) chronic (0.2.3) columnize (0.3.0) daemons (1.0.10) fastercsv (1.4.0) fastthread (1.0.7, 1.0.1) gem_plugin (0.2.3) googlecharts (1.3.6) hoe (1.12.2) javan-whenever (0.2.2) linecache (0.43) mislav-will_paginate (2.3.8) mongrel (1.1.5) mysql (2.7) passenger (2.2.2, 2.1.2) prawn (0.4.1) prawn-layout (0.1.0) rack (1.0.0, 0.9.1) rails (2.3.2, 2.2.2) rake (0.8.6, 0.8.4) ruby-debug (0.10.3) ruby-debug-base (0.10.3) ruby-net-ldap (0.0.4) rubyforge (1.0.3) sqlite3-ruby (1.2.4) technicalpickles-shoulda_generator (0.2.1) thoughtbot-factory_girl (1.2.1) thoughtbot-shoulda (2.10.1) [jlee@casweb5 mehmry]$ whenever . -bash: whenever: command not found
jeffleeismyhero
Mon Jun 01 07:09:37 -0700 2009
| link
[jlee@casweb5 mehmry]$ wheneverize . -bash: wheneverize: command not foundThis may just be a PATH issue. On my system (OS X) rubygems installed the whenever binary in /opt/local/bin/whenever. Perhaps the binary was installed somewhere outside of your path?
jeffleeismyhero
Mon Jun 01 07:17:48 -0700 2009
| link
Yes, I'm using Ruby Enterprise Edition so that was the issue. My path was the problem. Thanks!
I have the same problem. Other gems run normally. How can I set PATH for 'whenever'?
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.1 - RUBY VERSION: 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0] - INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8 - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby - EXECUTABLE DIRECTORY: /usr/binSo you're also running Ruby Enterprise Edition? First, you'll need to find the whenever binary. (If all else fails, run
find / --name "whenever")Then either supply the full path to whenever in your Capistrano task or set a PATH in your schedule.rb file like:
env :PATH, "/your/path:$PATH"
(you'll likely need to add more paths than just the one)
No Javan. I use Ruby 1.8.6 on localhost and can execute nor 'whenever' or 'wheneverize'. On my production server I use Ruby Enterprise Edition and Whenever works ideally.
Locally, did you install the gem using sudo? sudo gem install javan-whenever
I've tried but got only this:
could not find gem javan-wheneve locally or in a repositoryMy remote SOURCES:
- http://gems.rubyforge.org/ -
/usr/bin/env: rake: No such file or directory
2 comments Created 7 months ago by lardawgeif I go in and manually add the path to the rake file as follows:
30 2 * cd /site.com && RAILS_ENV=production /usr/bin/env /opt/ruby-enterprise/bin/rake db:users:clean >> /home/logs/cron_log.log 2>&1Things work. May I suggest retrieving the full path and inserting that for the rake executable? I am running on ubuntu 8.04.
Comments
I suggest setting a PATH environment variable in your schedule.rb file so your system knows where to find rake. Something like:
env :PATH, '/opt/ruby-enterprise/bin'
Another alternative is to define your path at the top of your crontab file. Run /bin/env or /usr/bin/env and then copy the line starting 'PATH=' into your crontab. For example, I have:
$ crontab -l PATH=/usr/java/jdk/bin:/usr/kerberos/bin:/usr/java/jdk/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/deploy/binBegin Whenever generated tasks ...
-
:at gets ignored when using shortcuts like :friday
1 comment Created 8 months ago by javanIf you're using something like 'every :friday' or 'every :weekday' setting :at will get ignored. This is a bummer if you want some to run, say, at 530pm on a Friday and it's hard to target a time like that otherwise.
Comments
-
Problem when two versions of the activesupport gem are installed
18 comments Created 8 months ago by javanIf two versions are installed, Whenever loads the newer one, and then if you try to use Whenever with a Rails app that requires the older version of the gem, it dies:
/usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:149:in activate': can't activate activesupport (= 2.1.1, runtime), already activated activesupport-2.3.2 (Gem::Exception) from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:165:in `activate' from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:164:in `each' from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:164:in `activate' from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:49:in `gem' from ./config/boot.rb:59:in `load_rails_gem' from ./config/boot.rb:53:in `load_initializer' from ./config/boot.rb:38:in `run' from ./config/boot.rb:11:in `boot!' ... 7 levels... from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in require' from /usr/local/lib/ruby/gems/1.8/gems/javan-whenever-0.1.7/bin/whenever:7 from /usr/local/bin/whenever:19:in `load' from /usr/local/bin/whenever:19Comments
fuzzylizard
Tue Jun 02 10:41:36 -0700 2009
| link
I am experiencing this bug as well with 2.2.2 and 2.3.2 installed on my production system. Here is my stack trace:
/usr/local/lib/site_ruby/1.8/rubygems.rb:149:in `activate': can't activate activesupport (= 2.2.2, runtime), already activated activesupport-2.3.2 (Gem::Exception)
from /usr/local/lib/site_ruby/1.8/rubygems.rb:165:in `activate' from /usr/local/lib/site_ruby/1.8/rubygems.rb:164:in `each' from /usr/local/lib/site_ruby/1.8/rubygems.rb:164:in `activate' from /usr/local/lib/site_ruby/1.8/rubygems.rb:49:in `gem' from ./config/boot.rb:59:in `load_rails_gem' from ./config/boot.rb:53:in `load_initializer' from ./config/boot.rb:38:in `run' from ./config/boot.rb:11:in `boot!' from ./config/boot.rb:109 from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from ./Rakefile:4 from /usr/lib/ruby/gems/1.8/gems/javan-whenever-0.3.0/lib/whenever.rb:6:in `load' from /usr/lib/ruby/gems/1.8/gems/javan-whenever-0.3.0/lib/whenever.rb:6 from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /usr/lib/ruby/gems/1.8/gems/javan-whenever-0.3.0/bin/whenever:7 from /usr/bin/whenever:19:in `load' from /usr/bin/whenever:19Thanks. The quick and dirty fix is to uninstall the version of activesupport you're not using. I'l get a fix in place soon.
joerichsen
Thu Jun 04 00:45:18 -0700 2009
| link
I have the same problem. Looking forward to the fix as whenever looks awesome :-)
+1 have this same issue. Going to try removing activesupport 2.3.2 since I'm not using it at the moment.
I am not using Rails 2.3 on my slice yet but I had some of the gems installed. I removed gems returned by
gem list | grep 2.3.2, re-deployed and verified the correct generated crontab file. Thanks.Just to ditto on the 2.2.2 vs 2.3.2 problem. I need both installed on my mac (personal projects are using 2.3.2, but work project using 2.2.2), so the workaround isn't an option. ::(
Removed activesupport dependency from gemspec. Closed by 6fbb125
Version 0.3.1 was just released and should fix this issue. Let me know if it doesn't.
anechanitzky
Thu Dec 10 07:09:51 -0800 2009
| link
Didn't work:
I got the message:
./Rakefile:3: undefined method `import' for main:Object (NoMethodError)from /usr/lib/ruby/gems/1.8/gems/javan-whenever-0.3.7/lib/whenever.rb:6:in `load' from /usr/lib/ruby/gems/1.8/gems/javan-whenever-0.3.7/lib/whenever.rb:6 from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /usr/lib/ruby/gems/1.8/gems/javan-whenever-0.3.7/bin/whenever:7 from /usr/bin/whenever:19:in `load' from /usr/bin/whenever:19while my gem list is:
actionmailer (2.3.4)
actionpack (2.3.4)
activemerchant (1.4.2, 1.4.1)
activerecord (2.3.4)
activerecord-tableless (0.1.0)
activeresource (2.3.4)
activesupport (2.3.4)
authlogic (2.1.3)
builder (2.1.2)
calendar_date_select (1.15)
capistrano (2.5.10)
chronic (0.2.3)
compass (0.8.17)
fastercsv (1.5.0)
fastthread (1.0.7)
git (1.2.5)
haml (2.2.15)
haml-edge (2.3.100)
highline (1.5.1)
hoe (2.3.3)
htmlentities (4.2.0)
javan-whenever (0.3.7)
json_pure (1.2.0)
mislav-will_paginate (2.3.11)
mysql (2.8.1)
net-scp (1.0.2)
net-sftp (2.0.4)
net-ssh (2.0.16)
net-ssh-gateway (1.0.1)
passenger (2.2.7)
rack (1.0.1)
rails (2.3.4)
rake (0.8.7)
RedCloth (4.2.2)
rmagick (2.12.2)
rsl-stringex (1.0.3)
rspec (1.2.9)
rspec-rails (1.2.9)
rubyforge (2.0.3)
rubyzip (0.9.1)
searchlogic (2.3.9)
spree (0.9.2)
tlsmail (0.0.1)
You're using an old version of the gem, please upgrade to the newest version (0.4.1 at the moment). Note that it is now hosted at gemcutter.org.
anechanitzky
Thu Dec 10 07:29:16 -0800 2009
| link
Thank you for the quick response. Unfortunately I still get the same error message:
./Rakefile:3: undefined method `import' for main:Object (NoMethodError)from /usr/lib/ruby/gems/1.8/gems/whenever-0.4.1/lib/whenever.rb:5:in `load' from /usr/lib/ruby/gems/1.8/gems/whenever-0.4.1/lib/whenever.rb:5 from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /usr/lib/ruby/gems/1.8/gems/whenever-0.4.1/bin/whenever:7 from /usr/bin/whenever:19:in `load' from /usr/bin/whenever:19It's choking when Whenever loads the Rakefile from your Rails (I assume) app. What's on line 3 of your Rakefile?
anechanitzky
Thu Dec 10 07:46:20 -0800 2009
| link
THe rakefile looks like this:
require 'rubygems'
require 'rake'require 'lib/whenever/version.rb'
begin
require 'jeweler' Jeweler::Tasks.new do |gemspec|gemspec.name = "whenever" gemspec.version = Whenever::VERSION gemspec.summary = "Clean ruby syntax for defining and deploying messy cron jobs." gemspec.description = "Clean ruby syntax for defining and deploying messy cron jobs." gemspec.email = "javan@javan.us" gemspec.homepage = "http://github.com/javan/whenever" gemspec.authors = ["Javan Makhmali"] gemspec.add_dependency("chronic", '>= 0.2.3')end Jeweler::GemcutterTasks.new rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install jeweler -s http://gemcutter.org" endrequire 'rake/testtask'
Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test' test.pattern = 'test/*.rb' test.verbose = true endtask :test => :check_dependencies
task :default => :test
So, line 3 is empty
That's Whenever's Rakefile.. Whenever tries to load the Rakefile from YOUR app, and it's dying on line 3 of it: "./Rakefile:3: undefined method `import' for main:Object (NoMethodError)"
anechanitzky
Thu Dec 10 07:52:47 -0800 2009
| link
Ah, my application's Rakefile does that in line 3:
import File.join(SPREE_ROOT, 'Rakefile')
And my application starts successfully
maybe change that "import" to "load"? i've never seen import in ruby.
anechanitzky
Thu Dec 10 07:59:58 -0800 2009
| link
That helps!
In Spree (www.spreecommerce.com) that Rakefile uses "import". I change it to "load"Thank you very much, javan!
Alexander












Do you need whenever within your Rails environment?
environment.rb:
deploy.rb:
Thank you granth, I followed the instruction in the README file but for some reason I missed to set :lib => false.