views:

360

answers:

2

I'm trying to use collectiveidea's delayed_job gem The installation instructions include

Rake tasks are not automatically loaded from gems, so you’ll need to add
the following to your Rakefile:

begin
  require 'delayed/tasks'
rescue LoadError
  STDERR.puts "Run `rake gems:install` to install delayed_job"
end

Where is my Rakefile? And what is a Rakefile?

+1  A: 

The Rakefile is a file that is used to configure rake, a Ruby build tool (sort of like make, but all in Ruby). In a Rails project, there is a file in the top project directory named Rakefile where you can insert this code.

Alternatively, you can add a file into the lib/tasks directory (for example named delayed_job.rake) and put the code into there. The name of the file is not important as long as

  1. It is in the lib/tasks directory
  2. It has the extension .rake
Rob Di Marco
Thanks Rob,It was right under my nose.
Mike
+1  A: 

I have the same problem and put that code in delayed_job.rake in the lib/tasks directory. It works, but now It say's:

*** Starting job worker localhost pid:79949 
rake aborted! 
uninitialized constant Delayed::Job

What is wrong now?

UPDATE: I just got a mail answer from Brandon:

Theres a bug in the latest version where it doesn't get properly initialized when using the rake task. If you create a file in config/initializers and put the follow in it, the error should go away:

Delayed::Worker.backend = :active_record
Markus