Resque Gem : For Background Processes In ROR
Elegant and fun? These phrases are not something you would associate with a programming language. Right? But this is exactly what Ruby on Rails is. Ruby on Rails, more commonly called as just Rails, is a pure object-oriented programming language with simple and user-friendly clean syntax. And by meaning simple and user-friendly, it means that you can get a web application ready much sooner than with any other programming language. To go live, all you need is web server and database. And of course, some gems! One of the best part about Ruby is the huge list of categorized, reusable codes suitably termed as "gems". The beauty of Ruby on Rails lies in the fact that with the help of these gems, you can create applications easily and with considerably less efforts as compared to other technologies. Read on to know about Rasque which is a gem to create background jobs.
Resque creates background jobs using Redis. Since it supports multiple queue, we can place them on multiple queues and process them later as well. And it comes with an administration interface for monitoring and managing the queues.
Resque is intended to be used in situations where high volume of job entries are required, and provides mechanisms to ensure reflectiveness and consistency of behaviour while providing statistics using a web dashboard.
When we have a long processing block of code which we don’t need to execute it inside our web application request cycle, a background processing queuing system is the only good solution. Hence we get faster performing ruby application.
Though Resque is inspired by DelayedJob to a great extent, if we need multiple queues in our APP, Resque is probably a better choice.
Choose Resque If:
- You require multiple queues
- You don’t particularly fancy numeric priorities
- You work with huge queues
- You work with Redis
- You’re not going to run short on RAM
Since there are a number of open source queuing systems available (delayed_job, beanstalk) we don’t need to write our own!
Here, it will go over how to setup the resque queuing system in a Ruby on Rails application.
Resque Setup:
bash:
brew install redis
redis-server /usr/local/etc/redis.conf
resque-web
rake resque:work QUEUE=’*’
Gemfile:
gem ‘resque’, :require => "resque/server"
Install the new gem:
bundle install
Create a redis config file called redis.yml in config:
defaults: &defaults