Rubygems (LoadError)

I’m trying to set up a cron job with a runner that calls a method in one
of my models. I’m using javan’s whenever gem to do this and I’m running
CentOS on my server. Whenever the cron executes though I’m getting the
following error:

`require’: no such file to load – rubygems (LoadError)

The method uses the ‘mail’ and ‘nokogiri’ gems. I tried cron again by
including ‘require rubygems’ as well, but that doesn’t seem to help. I
suspect that it may be a problem with my path variables.

Any advice on how to fix this though? Thanks, any help would be really
appreciated.

On 27 Apr 2011, at 17:24, Sayem I. [email protected] wrote:

I’m trying to set up a cron job with a runner that calls a method in one
of my models. I’m using javan’s whenever gem to do this and I’m running
CentOS on my server. Whenever the cron executes though I’m getting the
following error:

How is ruby installed on your server?

Fred

Frederick C. wrote in post #995357:

How is ruby installed on your server?

Fred

Thanks for the response, Fred. When I run the method within terminal it
works with no problem, I’m just getting these gem issues with cron.

ruby -v shows the following:

ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]

and gem environment shows:

  • RUBY VERSION: 1.9.2 (2011-02-18 patchlevel 180) [x86_64-linux]

On Wed, Apr 27, 2011 at 12:39 PM, Sayem I. [email protected]
wrote:

  • RUBY VERSION: 1.9.2 (2011-02-18 patchlevel 180) [x86_64-linux]

cron by default uses a more restrictive set of environment variables.
You may need
to tweak the jobs settings so that everything is set correctly in the
variables (from what
I can remember off the top of my head):

PATH (make sure cron can find all the binaries it needs),
LANG (make sure the encoding is the same, en_US is crons default
IIRC, and it may need en_US.utf8),
RUBYOPT,
RAILS_GEM_VERSION,
GEM_HOME,
GEM_PATH

It may be a good idea to run a junk cron job in there to just run the
‘set’ command
and dump it out to a file so you can see what environment cron has
when trying to
run by default.

-J

Jason Stover wrote in post #995372:

PATH (make sure cron can find all the binaries it needs),
LANG (make sure the encoding is the same, en_US is crons default
IIRC, and it may need en_US.utf8),
RUBYOPT,
RAILS_GEM_VERSION,
GEM_HOME,
GEM_PATH

It may be a good idea to run a junk cron job in there to just run the
‘set’ command
and dump it out to a file so you can see what environment cron has
when trying to
run by default.

-J

Thanks a lot, Jason. Yeah, I figured it was my path and I also noticed
that ‘which ruby’ showed that I was using two different locations, so I
put in my $PATH at the top of my cron and that fixed the LoadError.

I’m not getting that anymore, however now I’m getting the following
SQLException when using cron:

runner.rb:50:in `eval’: SQLite3::SQLException: no such table: users:
SELECT “users”.* FROM “users” (ActiveRecord::StatementInvalid)

Jason Stover wrote in post #995384:

Hrmm… if your database is correct, then I’d say be sure to pass the
correct RAILS_ENV paramater to cron… like:

          • /usr/bin/env RAILS_ENV=development /usr/local/bin/ruby
            [path to]/somescript.rb

-J

You’re the man, Jason. Thanks a lot! That sure did the trick.
Cron/whenever is now fully working.

On Wed, Apr 27, 2011 at 2:40 PM, Sayem I. [email protected]
wrote:

I’m not getting that anymore, however now I’m getting the following
SQLException when using cron:

runner.rb:50:in `eval’: SQLite3::SQLException: no such table: users:
SELECT “users”.* FROM “users” (ActiveRecord::StatementInvalid)

Hrmm… if your database is correct, then I’d say be sure to pass the
correct RAILS_ENV paramater to cron… like:

          • /usr/bin/env RAILS_ENV=development /usr/local/bin/ruby
            [path to]/somescript.rb

-J

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs