Resque/Background jobs Flashcards

1
Q

What is Resque?

A

Redis-backed library for creating background jobs, placing those jobs on multiple queues, and processing them later.

Background jobs can be any Ruby class or module that responds to perform. Your existing classes can easily be converted to background jobs or you can create new classes specifically to do work. Or, you can do both.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Resque is inspired by ____ and is comprised of 3 parts

A

DelayedJob

1. A Ruby library for creating, querying, and processing jobs
2. A Rake task for starting a worker which processes jobs
3. A Sinatra app for monitoring queues, jobs, and workers.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Using Resque

A

Resque allows you to create jobs and place them on a queue, then, later, pull those jobs off the queue and process them.

Resque jobs are Ruby classes (or modules) which respond to the perform method. Here’s an example:

class Archive
  @queue = :file_serve
  def self.perform(repo_id, branch = 'master')
    repo = Repository.find(repo_id)
    repo.create_archive(branch)
  end
end

The @queue class instance variable determines which queue Archive jobs will be placed in. Queues are arbitrary and created on the fly - you can name them whatever you want and have as many as you want.

To place an Archive job on the file_serve queue, we might add this to our application’s pre-existing Repository class:

class Repository
  def async_create_archive(branch)
    Resque.enqueue(Archive, self.id, branch)
  end
end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly