lingui.st Translating software made easy

Resque Jobs automatically require Rails environment and Lib Classes

Posted on July 26, 2010

Like I mentioned in my last article, I currently use Redis/Resque quite a bit. The installation of Redis isn’t really a challenge and Resque isn’t more than a requirement in the Gemfile. However, I often forget that when I start a Resque worker, it doesn’t have access to the Environment/Lib files per default. A “class not found” exception is the typical indicator.

When you are working with Rails, the Rake task “resque:setup” seems the right place to require everything necessary. Just create a new File named “resque.rake” under the folder “lib/tasks“. Rails loads .rake files automatically from this folder. Next, put the following in the file:

It extends the “resque:setup” task, so that the Rails environment and also all Ruby files from the folder “lib/hemju/jobs” are required on the setup. When you are creating a new Resque Job, just put it under the /lib/hemju/jobs folder and the Worker has access to. Don’t forget to restart the worker.

Lingui.st - Online Resource Editor, Manage your Ruby/Rails, Java, .Net and C++ language files with ease

Related posts:

  1. Rake task for quitting Resque workers
  2. Adding ‘whenever’ gem to Rails environment caused warning
  3. Rails: Cron Job Scheduling using Redis, Resque and Rufus
  4. Speed up your website with CDN and Rails

Tags: , , , ,