Giter VIP home page Giter VIP logo

whenever's Introduction

Whenever is a Ruby gem that provides a clear syntax for writing and deploying cron jobs.

Installation

$ gem install whenever

Or with Bundler in your Gemfile.

gem 'whenever', require: false

Getting started

$ cd /apps/my-great-project
$ bundle exec wheneverize .

This will create an initial config/schedule.rb file for you (as long as the config folder is already present in your project).

The whenever command

The whenever command will simply show you your schedule.rb file converted to cron syntax. It does not read or write your crontab file.

$ cd /apps/my-great-project
$ bundle exec whenever

To write your crontab file for your jobs, execute this command:

$ whenever --update-crontab

Other commonly used options include:

$ whenever --user app # set a user as which to install the crontab
$ whenever --load-file config/my_schedule.rb # set the schedule file
$ whenever --crontab-command 'sudo crontab' # override the crontab command

Note: If you run the whenever --update-crontab without passing the --user attribute, cron will be generated by the current user. This mean tasks that needs other user permission will fail.

You can list installed cron jobs using crontab -l.

Run whenever --help for a complete list of options for selecting the schedule to use, setting variables in the schedule, etc.

Example schedule.rb file

every 3.hours do # 1.minute 1.day 1.week 1.month 1.year is also supported
  # the following tasks are run in parallel (not in sequence)
  runner "MyModel.some_process"
  rake "my:rake:task"
  command "/usr/bin/my_great_command"
end

every 1.day, at: '4:30 am' do
  runner "MyModel.task_to_run_at_four_thirty_in_the_morning"
end

every 1.day, at: ['4:30 am', '6:00 pm'] do
  runner "Mymodel.task_to_run_in_two_times_every_day"
end

every :hour do # Many shortcuts available: :hour, :day, :month, :year, :reboot
  runner "SomeModel.ladeeda"
end

every :sunday, at: '12pm' do # Use any day of the week or :weekend, :weekday
  runner "Task.do_something_great"
end

every '0 0 27-31 * *' do
  command "echo 'you can use raw cron syntax too'"
end

# run this task only on servers with the :app role in Capistrano
# see Capistrano roles section below
every :day, at: '12:20am', roles: [:app] do
  rake "app_server:task"
end

Define your own job types

Whenever ships with three pre-defined job types: command, runner, and rake. You can define your own with job_type.

For example:

job_type :awesome, '/usr/local/bin/awesome :task :fun_level'

every 2.hours do
  awesome "party", fun_level: "extreme"
end

Would run /usr/local/bin/awesome party extreme every two hours. :task is always replaced with the first argument, and any additional :whatevers are replaced with the options passed in or by variables that have been defined with set.

The default job types that ship with Whenever are defined like so:

job_type :command, ":task :output"
job_type :rake,    "cd :path && :environment_variable=:environment bundle exec rake :task --silent :output"
job_type :runner,  "cd :path && bin/rails runner -e :environment ':task' :output"
job_type :script,  "cd :path && :environment_variable=:environment bundle exec script/:task :output"

Pre-Rails 3 apps and apps that don't use Bundler will redefine the rake and runner jobs respectively to function correctly.

If a :path is not set it will default to the directory in which whenever was executed. :environment_variable will default to 'RAILS_ENV'. :environment will default to 'production'. :output will be replaced with your output redirection settings which you can read more about here: http://github.com/javan/whenever/wiki/Output-redirection-aka-logging-your-cron-jobs

All jobs are by default run with bash -l -c 'command...'. Among other things, this allows your cron jobs to play nice with RVM by loading the entire environment instead of cron's somewhat limited environment. Read more: http://blog.scoutapp.com/articles/2010/09/07/rvm-and-cron-in-production

You can change this by setting your own :job_template.

set :job_template, "bash -l -c ':job'"

Or set the job_template to nil to have your jobs execute normally.

set :job_template, nil

Parsing dates and times

Whenever uses the Chronic gem to parse the specified dates and times.

You can set your custom Chronic configuration if the defaults don't fit you.

For example, to assume a 24 hour clock instead of the default 12 hour clock:

set :chronic_options, hours24: true

# By default this would run the job every day at 3am
every 1.day, at: '3:00' do
  runner "MyModel.nightly_archive_job"
end

You can see a list of all available options here: https://github.com/mojombo/chronic/blob/master/lib/chronic/parser.rb

Customize email recipient with the MAILTO environment variable

Output from the jobs is sent to the email address configured in the MAILTO environment variable.

There are many ways to further configure the recipient.

Example: A global configuration, overriding the environment's value:

env 'MAILTO', '[email protected]'

every 3.hours do
  command "/usr/bin/my_great_command"
end

Example: A MAILTO configured for all the jobs in an interval block:

every 3.hours, mailto: '[email protected]'  do
  command "/usr/bin/my_super_command"
end

Example: A MAILTO configured for a single job:

every 3.hours do
  command "/usr/bin/my_super_command", mailto: '[email protected]'
end

Capistrano integration

Use the built-in Capistrano recipe for easy crontab updates with deploys. For Capistrano V3, see the next section.

In your "config/deploy.rb" file:

require "whenever/capistrano"

Take a look at the recipe for options you can set. https://github.com/javan/whenever/blob/master/lib/whenever/capistrano/v2/recipes.rb For example, if you're using bundler do this:

set :whenever_command, "bundle exec whenever"
require "whenever/capistrano"

If you are using different environments (such as staging, production), then you may want to do this:

set :whenever_environment, defer { stage }
require "whenever/capistrano"

The capistrano variable :stage should be the one holding your environment name. This will make the correct :environment available in your schedule.rb.

If both your environments are on the same server you'll want to namespace them, or they'll overwrite each other when you deploy:

set :whenever_environment, defer { stage }
set :whenever_identifier, defer { "#{application}_#{stage}" }
require "whenever/capistrano"

If you use a schedule at an alternative path, you may configure it like so:

set :whenever_load_file, defer { "#{release_path}/somewhere/else/schedule.rb" }
require "whenever/capistrano"

Capistrano V3 Integration

In your "Capfile" file:

require "whenever/capistrano"

Take a look at the load:defaults task (bottom of file) for options you can set. For example, to namespace the crontab entries by application and stage do this in your "config/deploy.rb" file:

set :whenever_identifier, ->{ "#{fetch(:application)}_#{fetch(:stage)}" }

The Capistrano integration by default expects the :application variable to be set in order to scope jobs in the crontab.

Capistrano roles

The first thing to know about the new roles support is that it is entirely optional and backwards-compatible. If you don't need different jobs running on different servers in your capistrano deployment, then you can safely stop reading now and everything should just work the same way it always has.

When you define a job in your schedule.rb file, by default it will be deployed to all servers in the whenever_roles list (which defaults to [:db]).

However, if you want to restrict certain jobs to only run on subset of servers, you can add a roles: [...] argument to their definitions. Make sure to add that role to the whenever_roles list in your deploy.rb.

When you run cap deploy, jobs with a :roles list specified will only be added to the crontabs on servers with one or more of the roles in that list.

Jobs with no :roles argument will be deployed to all servers in the whenever_roles list. This is to maintain backward compatibility with previous releases of whenever.

So, for example, with the default whenever_roles of [:db], a job like this would be deployed to all servers with the :db role:

every :day, at: '12:20am' do
  rake 'foo:bar'
end

If we set whenever_roles to [:db, :app] in deploy.rb, and have the following jobs in schedule.rb:

every :day, at: '1:37pm', roles: [:app] do
  rake 'app:task' # will only be added to crontabs of :app servers
end

every :hour, roles: [:db] do
  rake 'db:task' # will only be added to crontabs of :db servers
end

every :day, at: '12:02am' do
  command "run_this_everywhere" # will be deployed to :db and :app servers
end

Here are the basic rules:

  1. If a server's role isn't listed in whenever_roles, it will never have jobs added to its crontab.
  2. If a server's role is listed in the whenever_roles, then it will have all jobs added to its crontab that either list that role in their :roles arg or that don't have a :roles arg.
  3. If a job has a :roles arg but that role isn't in the whenever_roles list, that job will not be deployed to any server.

RVM Integration

If your production environment uses RVM (Ruby Version Manager) you will run into a gotcha that causes your cron jobs to hang. This is not directly related to Whenever, and can be tricky to debug. Your .rvmrc files must be trusted or else the cron jobs will hang waiting for the file to be trusted. A solution is to disable the prompt by adding this line to your user rvm file in ~/.rvmrc

rvm_trust_rvmrcs_flag=1

This tells rvm to trust all rvmrc files.

Heroku?

No. Heroku does not support cron, instead providing Heroku Scheduler. If you deploy to Heroku, you should use that rather than Whenever.

Testing

whenever-test is an extension to Whenever for testing a Whenever schedule.

Credit

Whenever was created for use at Inkling (http://inklingmarkets.com). Their take on it: http://blog.inklingmarkets.com/2009/02/whenever-easy-way-to-do-cron-jobs-from.html

Thanks to all the contributors who have made it even better: http://github.com/javan/whenever/contributors

Discussion / Feedback / Issues / Bugs

For general discussion and questions, please use the google group: http://groups.google.com/group/whenever-gem

If you've found a genuine bug or issue, please use the Issues section on github: http://github.com/javan/whenever/issues

Ryan Bates created a great Railscast about Whenever: http://railscasts.com/episodes/164-cron-in-ruby It's a little bit dated now, but remains a good introduction.


Build Status


Copyright © 2017 Javan Makhmali

whenever's People

Contributors

amiryal avatar andfx avatar andrew avatar bartkozal avatar benlangfeld avatar bragamat avatar cap10morgan avatar dce avatar dinossaur23 avatar felixbuenemann avatar javan avatar jeroenj avatar kibitan avatar lostapathy avatar moskvin avatar niklas avatar olleolleolle avatar p avatar phallstrom avatar rubys avatar samuelokrent avatar seanhandley avatar stevenwilliamson avatar stve avatar szajbus avatar ta1kt0me avatar timcraft avatar ttilberg avatar yob avatar zibs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

whenever's Issues

'whenever' (no args) output is incorrect

I run whenever and do a --set environment=development

When I do a 'crontab -l', it shows the job, using RAILS_ENV=development as the correct environment... However, when I do a 'whenever' by itself, it incorrectly shows the job will run with RAILS_ENV=production. Upon testing, the job correctly runs under development as 'crontab -l' indicates. So there must be some error when 'whenever' is reading the crontab. See terminal output below


>> whenever --update-crontab nmalirt --set environment=development
[write] crontab file updated
>> crontab -l
# m h  dom mon dow   command

# Begin Whenever generated tasks for: nmalirt
PATH=/opt/local/bin:/opt/local/sbin:/Users/istrascina/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin:/Users/istrascina/bin:/usr/local/mysql/bin

0 8 20 * * cd /Users/istrascina/dev/rails/nmalirt && RAILS_ENV=development /usr/bin/env rake mail:reminders


# End Whenever generated tasks for: nmalirt
>> whenever
PATH=/opt/local/bin:/opt/local/sbin:/Users/istrascina/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin:/Users/istrascina/bin:/usr/local/mysql/bin

0 8 20 * * cd /Users/istrascina/dev/rails/nmalirt && RAILS_ENV=production /usr/bin/env rake mail:reminders

Sending email

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')

set environment=development does not work

Macintosh-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>&1

whenever command can't find my Rails gem version

I 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?

Problem with vendorised version

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 :)

wheneverize: command not found

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.

Whenever and Capistrano incompatibility

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.rb file you load the project Rakefile.

# Hoping to load Rails' Rakefile
begin
  load 'Rakefile'
rescue LoadError
  nil
end

The Rakefile requires rake which inject the FileUtils into the current Ruby scope. FileUtils provide a Object#symlink method which goes in conflict with Capistrano. Here's the original source.

Now the question is: why do you need to load the Rakefile in the whenever.rb file? It only seems to contain tasks focused on packaging and releasing the Gem. It also includes the version.rb file, but you can easily copy the statement in whenever.rb.

In this way, you will make your library compatible with Capistrano.

Problem when two versions of the activesupport gem are installed

If 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:

<pre> /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:19

:at parameter doesn't work with 1.month

Hi,

Using :
every 1.month, :at => '4:00 am' do
--do something

end

produces in the crontab:
0 4 5 * *

So the correct hour, but not the correct month value.... As it should be expecting 0 4 1.

Cheers,

Tom

Smart-grouping code dying on mixed hourly/daily tasks

I'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"
end

Continuous crontab comment addition

For some reason, every time whenever adds 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.

application name prefix confuses update-crontab

I have a Rails app running in two environments to serve two countries.

The first whenever call setup most of the tasks (country independent), the second and third run the few that must be run for both countries (environments).

whenever --update-crontab myapp --set environment=staging_au && whenever --update-crontab myapp_au --set environment=staging_au --load-file config/schedule_both_countries.rb && whenever --update-crontab myapp_nz --set environment=staging_nz --load-file config/schedule_both_countries.rb

It will work the first time, but each time you update the cronjob after the file will get corrupted.
Seems like naming them au_myapp and nz_myapp is enough to solve it.

whenever --update-crontab myapp --set environment=staging_au && whenever --update-crontab au_myapp --set environment=staging_au --load-file config/schedule_both_countries.rb && whenever --update-crontab nz_myapp --set environment=staging_nz --load-file config/schedule_both_countries.rb

Capistrano says crontab written, but crontab -l doesn’t indicate that it was

I’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.

[Feature Request] support custom system environment variables on cron

now, whenever's rake command has been supports custom system environment, for example:

every :hour do
  rake "app:do_something LOG=STDOUT", :output => 'log/something.log'
end

will output

@hourly cd /Users/sunteya/Workspaces/project && RAILS_ENV=production /usr/bin/env rake app:do_something LOG=STDOUT >> log/something.log 2>&1

but the runner command not, i hope that the runner can also support custom environment variables, ex:

runner "App.do_something", :output => 'log/something.log', :env => { "LOG" => "STDOUT" }

output

@hourly LOG=STDOUT /Users/sunteya/Workspaces/project/script/runner -e production "App.do_something" >> log/something.log 2>&1

Chronic dependency depends on Hoe

I would submit a patch to chronic, but it seems like mojombo isn't really updating chronic anymore. It looks like evaryont/chronic has been updated much more recently and doesn't have the dependency on hoe. Not sure if you want to change the chronic dependency or try to get mojombo to push a new version of chronic, but it would be nice to not have the extra dependency for whenever, especially when bundling it.

/usr/bin/env: rake: No such file or directory

if 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>&1

Things work. May I suggest retrieving the full path and inserting that for the rake executable? I am running on ubuntu 8.04.

Bundler::GemfileNotFound when ran from absolute path

Since we moved our app to Bundler, cron jobs (created by whenever) don't want to run, as bundler expects to find Gemfile in the directory the script/runner is ran from.

So, for instance
/u/apps/myapp/releases/20100318100534/script/runner -e production "Model.do_something"
doesn't work and throws this error.

Any chance to make the cron line generate in this manner?
cd /u/apps/myapp/releases/20100318100534; script/runner -e production "Model.do_something"

Whenever just isn't working for me...here is what i have done

-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 x

Wheneverize command not found on Dreamhost

I'm running a rails app on Dreamhost servers. I install the gem Whenever just fine. But when I run:
[code]wheneverize .[/code]
I get:
[code]-bash: wheneverize: command not found[/code]
Any ideas on what I'm doing wrong or what I should do next?

Thanks so much!

Changing environments with whenever (--set is not working)

I 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!

Whenever, Rake and Model name Conflict

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.

whenever updates crontab with no newline before EOL/EOF

I 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/+viewstatus

Not 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.

Rake jobs don't run in some environments

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.

"every :sunday" fails on Solaris

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?

crontab defaults to production

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.

How can I load different schedule.rb files for different environments?

I 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!

Conditional task execution depending on environment

I 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 do
rake 'some_task'
end
end

similarly, I've tried:

if Rails.env.production?
every 2.hours do
rake '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?

Specify day on monthly jobs

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...

Multiple environments overwrites crontab to last

Seems 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 -l

Begin 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

:at gets ignored when using shortcuts like :friday

If 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.

every :day, :at => '9am' fails on OS X

Here is the task:
every :day, :at => '9am' do
rake "util:blah"
end

Here 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)

Crontab unexpected character found in line

My schedule.rb:
every 10.minutes do
runner "EmailList.send_mails"
end

When i deploy I get:
*** [err :: blah.aptanacloud.com] PATH=/opt/local/bin:/opt/local/sbin:/usr/bin:/usr/sbin:/usr/sfw/bin:/usr/ucb:/etc:.
*** [err :: blah.aptanacloud.com] crontab: error on previous line; unexpected character found in line.
*** [err :: blah.aptanacloud.com]
*** [err :: blah.aptanacloud.com] crontab: errors detected in input, no crontab file generated.
** [out :: blah.aptanacloud.com] [write] crontab file updated

Sorry, I'm just a newbie... but what is going on? I've never used Crontab before.

It doesn't convert with zones

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"

comparison of Time with 0 failed

when calling whenever, i get this error:

/opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/whenever-0.4.0/lib/whenever/outputs/cron.rb:63:in >': comparison of Time with 0 failed (ArgumentError) from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/whenever-0.4.0/lib/whenever/outputs/cron.rb:63:inparse_symbol'
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/whenever-0.4.0/lib/whenever/outputs/cron.rb:39:in time_in_cron_syntax' from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/whenever-0.4.0/lib/whenever/outputs/cron.rb:34:inoutput'
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/whenever-0.4.0/lib/whenever/outputs/cron.rb:28:in output' from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/whenever-0.4.0/lib/whenever/outputs/cron.rb:27:ineach'
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/whenever-0.4.0/lib/whenever/outputs/cron.rb:27:in output' from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/whenever-0.4.0/lib/whenever/outputs/cron.rb:26:ineach'
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/whenever-0.4.0/lib/whenever/outputs/cron.rb:26:in output' ... 8 levels... from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/whenever-0.4.0/lib/whenever/command_line.rb:5:inexecute'
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/whenever-0.4.0/bin/whenever:30
from /home/frexuz/.gem/ruby/1.8/bin/whenever:19:in `load'
from /home/frexuz/.gem/ruby/1.8/bin/whenever:19

using ubuntu 8.04 with REE and passenger

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.