Resque Jobs automatically require Rails environment and Lib Classes
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.
Related posts:
Tags: Background Jobs, Performance, Rails, Redis, Resque