Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to test in development environment? #351

Closed
fabianoalmeida opened this issue Jun 10, 2013 · 5 comments
Closed

How to test in development environment? #351

fabianoalmeida opened this issue Jun 10, 2013 · 5 comments

Comments

@fabianoalmeida
Copy link

I have a cron on my app and I'm trying to test it, but it's not running. My config:

# Gemfile
gem 'whenever', require: false

My schedule

# config/schedule.rb
set :output, { error: 'error.log', standard: 'cron.log' }

every 2.minutes do
  runner "Cron.get_categories"
end

And my cron

# lib/cron.rb
class Cron
  def self.get_categories
    p "Testing..."
  end
end

And the text is not printing on my console. Is there any other configuration to do?

Thanks in advance!

@javan
Copy link
Owner

javan commented Jun 10, 2013

To update your local crontab in development mode, you'll need to run the whenever command manually, instead of relying on the included Capistrano tasks to do it for you. whenever --update-crontab --set environment=development should do the trick.

From there, you can run crontab -l to ensure that your crontab file was written. Your job should be running every 2 minutes now. Note, you won't ever see any text in your console; the runner occurs in a new process

@javan javan closed this as completed Jun 10, 2013
@fabianoalmeida
Copy link
Author

Thanks @javan! However, this didn't work for me. I ran:

$ whenever --update-crontab --set environment=development
# => [write] crontab file updated

$ crontab -l
# => # Begin Whenever generated tasks for: config/schedule.rb
# => 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * /bin/bash -l -c 'cd /Users/app && script/rails runner -e production '\''Cron.get_categories'\'' >> log/cron.log 2>> log/error.log'

# => # End Whenever generated tasks for: config/schedule.rb

# => # Begin Whenever generated tasks for: /Users/app/config/schedule.rb
# => * * * * * /bin/bash -l -c 'cd /Users/app && script/rails runner -e development '\''Cron.get_categories'\'' >> log/cron.log 2>> log/error.log'

# => # End Whenever generated tasks for: /Users/app/config/schedule.rb

And nothing happened. 😕 I'm using a Mac OSX (10.8.3 version), Rails 3.2.13 and Ruby 2.0.0.

Your answer left me a doubt... This means that to use whenever in production environment I need to install capistrano gem, right?

Another question... If I create a new cron or just update the time that each cron will run, I need execute this command again?

Thank you so much @javan!

@javan
Copy link
Owner

javan commented Jun 11, 2013

Check your log/cron.log file, I suspect it's being written to every 2 minutes.

If you're using Capistrano to deploy your application, Whenever has built-in tasks to write your crontab. They're not required though, it can always be used as a command line tool.

@fabianoalmeida
Copy link
Author

This is the error:

# log/error.log
/Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:45:in `gem_original_require': no such file to load -- bundler/setup (LoadError)
    from /Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:45:in `require'
    from /Users/app/config/boot.rb:6
    from script/rails:5:in `require'
    from script/rails:5

And this on my boot.rb

# config/boot.rb at line 6
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])

@lgs
Copy link

lgs commented Mar 20, 2015

@fabianoalmeida in your local crontab, instead of

* * * * * /bin/bash -l -c 'cd /Users/app && script/rails runner -e development '\''Cron.get_categories'\'' >> log/cron.log 2>> log/error.log'

run the command with bundle exec:

* * * * * /bin/bash -l -c 'cd /Users/app && /your-full-path-to/bundle exec script/rails runner -e development '\''Cron.get_categories'\'' >> log/cron.log 2>> log/error.log'

... to find out your full path to bundle, just run which unix command like the following:

$ which bundle
/home/lsoave/.rbenv/shims/bundle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants