Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rake tasks from cron - uninitialized constant YAML::ENGINE

I am getting uninitialized constant YAML::ENGINE when running a rake task from cron since I upgraded my server to ruby 1.9.2. I had the same error with the app but putting ...

require 'yaml'
YAML::ENGINE.yamler= 'syck'

in the boot.rb file fixed it. If I run the task directly from the command line on my Ubuntu server it works fine, the server uses RVM.

However running a task from cron doesn't seem to pickup this fix, I have tried this ...

task :twitter, :needs => :environment do
  require 'yaml'
  YAML::ENGINE.yamler= 'syck'
  @tweets = Property.updatetwitter
end

to no avail.

like image 376
creativetechnologist Avatar asked Nov 22 '25 14:11

creativetechnologist


1 Answers

Are you sure you're running it under Ruby 1.9.2? Because while YAML::ENGINE exists in 1.9.2, it's not in 1.8.7. Check your Ruby version.

UPDATE

How to tell which Ruby version program is using from within the program:

puts `ruby -v`

Lame way how to enforce cron task to run under certain Ruby version (if server uses RVM):

rvm use 1.8.7; ...
like image 159
Lukas Stejskal Avatar answered Nov 25 '25 09:11

Lukas Stejskal