<commit_before>Resque
======

[![Gem Version](https://badge.fury.io/rb/resque.svg)](https://rubygems.org/gems/resque)
[![Build Status](https://travis-ci.org/resque/resque.svg)](https://travis-ci.org/resque/resque)

Resque (pronounced like "rescue") is 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.

Resque is heavily inspired by DelayedJob (which rocks) and comprises
three parts:

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.

Resque workers can be distributed between multiple machines,
support priorities, are resilient to memory bloat / "leaks," are
optimized for REE (but work on MRI and JRuby), tell you what they're
doing, and expect failure.

Resque queues are persistent; support constant time, atomic push and
pop (thanks to Redis); provide visibility into their contents; and
store jobs as simple JSON packages.

The Resque frontend tells you what workers are doing, what workers are
not doing, what queues you're using, what's in those queues, provides
general usage stats, and helps you track failures.

Resque now supports Ruby 2.3.0 and above.
We will also only be supporting Redis 3.0 and above going forward.


Table of Contents
-----------------

* [Overview](#overview)
* [Installation](#installation)
* [Running Workers](#running-workers)
* [The Front End](#the-front-end)
* [Jobs](#jobs)
* [Configuration](#configuration)
* * [Redis](#redis)
* * [Logging](#logging)
* * [Namespaces](#namespaces)
* * [Storing Statistics](#storing-statistics)
* [Plugins and Hooks](#plugins-and-hooks)
* [Additional Information](#additional-information)
* * [Resque vs DelayedJob](#resque-vs-delayedjob)
* * [Forking](#forking)
* * [Signals](#signals)
* * [Heroku](#heroku)
* * [Monitoring](#monitoring)
* * [Mysql::Error](#mysqlerror-mysql-server-has-gone-away)
* [Development](#development)
* * [Demo](#demo)
* * [Contributing](#contributing)
* [Questions](#questions)
* [Meta](#meta)
* [Author](#author)

Overview
--------

For the backstory, philosophy, and history of Resque's beginnings, please see [the blog post](http://github.com/blog/542-introducing-resque).

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:


``` ruby
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:

``` ruby
class Repository
  def async_create_archive(branch)
    Resque.enqueue(Archive, self.id, branch)
  end
end
```

Now when we call `repo.async_create_archive('masterbrew')` in our
application, a job will be created and placed on the `file_serve`
queue.

Later, a worker will run something like this code to process the job:

``` ruby
klass, args = Resque.reserve(:file_serve)
klass.perform(*args) if klass.respond_to? :perform
```

Which translates to:

``` ruby
Archive.perform(44, 'masterbrew')
```

Let's start a worker to run `file_serve` jobs:

    $ cd app_root
    $ QUEUE=file_serve rake resque:work

This starts one Resque worker and tells it to work off the
`file_serve` queue. As soon as it's ready it'll try to run the
`Resque.reserve` code snippet above and process jobs until it can't
find any more, at which point it will sleep for a small period and
repeatedly poll the queue for more jobs.

Workers can be given multiple queues (a "queue list") and run on
multiple machines. In fact they can be run anywhere with network
access to the Redis server.

Installation
------------

Add the gem to your Gemfile:

    gem 'resque'

Next, install it with Bundler:<commit_msg>Update README with Rails example<commit_after>Resque
======

[![Gem Version](https://badge.fury.io/rb/resque.svg)](https://rubygems.org/gems/resque)
[![Build Status](https://travis-ci.org/resque/resque.svg)](https://travis-ci.org/resque/resque)

Resque (pronounced like "rescue") is 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.

Resque is heavily inspired by DelayedJob (which rocks) and comprises
three parts:

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.

Resque workers can be distributed between multiple machines,
support priorities, are resilient to memory bloat / "leaks," are
optimized for REE (but work on MRI and JRuby), tell you what they're
doing, and expect failure.

Resque queues are persistent; support constant time, atomic push and
pop (thanks to Redis); provide visibility into their contents; and
store jobs as simple JSON packages.

The Resque frontend tells you what workers are doing, what workers are
not doing, what queues you're using, what's in those queues, provides
general usage stats, and helps you track failures.

Resque now supports Ruby 2.3.0 and above.
We will also only be supporting Redis 3.0 and above going forward.


Table of Contents
-----------------

* [Overview](#overview)
* [Installation](#installation)
* [Running Workers](#running-workers)
* [The Front End](#the-front-end)
* [Jobs](#jobs)
* [Configuration](#configuration)
* * [Redis](#redis)
* * [Logging](#logging)
* * [Namespaces](#namespaces)
* * [Storing Statistics](#storing-statistics)
* [Plugins and Hooks](#plugins-and-hooks)
* [Additional Information](#additional-information)
* * [Resque vs DelayedJob](#resque-vs-delayedjob)
* * [Forking](#forking)
* * [Signals](#signals)
* * [Heroku](#heroku)
* * [Monitoring](#monitoring)
* * [Mysql::Error](#mysqlerror-mysql-server-has-gone-away)
* [Development](#development)
* * [Demo](#demo)
* * [Contributing](#contributing)
* [Questions](#questions)
* [Meta](#meta)
* [Author](#author)

Overview
--------

For the backstory, philosophy, and history of Resque's beginnings, please see [the blog post](http://github.com/blog/542-introducing-resque).

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:


``` ruby
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:

``` ruby
class Repository
  def async_create_archive(branch)
    Resque.enqueue(Archive, self.id, branch)
  end
end
```

Now when we call `repo.async_create_archive('masterbrew')` in our
application, a job will be created and placed on the `file_serve`
queue.

Later, a worker will run something like this code to process the job:

``` ruby
klass, args = Resque.reserve(:file_serve)
klass.perform(*args) if klass.respond_to? :perform
```

Which translates to:

``` ruby
Archive.perform(44, 'masterbrew')
```

Let's start a worker to run `file_serve` jobs:

    $ cd app_root
    $ QUEUE=file_serve rake resque:work

This starts one Resque worker and tells it to work off the
`file_serve` queue. As soon as it's ready it'll try to run the
`Resque.reserve` code snippet above and process jobs until it can't
find any more, at which point it will sleep for a small period and
repeatedly poll the queue for more jobs.

Workers can be given multiple queues (a "queue list") and run on
multiple machines. In fact they can be run anywhere with network
access to the Redis server.

#### Rails example

If you installed the Resque as a Rails gem, the above example will look like this:

``` ruby
class ArchiveJob < ApplicationJob
  queue_as :file_serve

  def perform(repo_id, branch = 'master')
    repo = Repository.find(repo_id)
    repo.create_archive(branch)
  end
end
```

``` ruby
class Repository
  def async_create_archive(branch)
    ArchiveJob.perform_later(self.id, branch)
  end
end
```

It is important to run `ArchiveJob.perform_later(self.id, branch)` rather than `Resque.enqueue(Archive, self.id, branch)`.
Otherwise the Resque will process the job without actually doing anything.
Even if you put obviously buggy line like `0/0` in the `perform` method,
the job will still succeed.

Installation
------------

Add the gem to your Gemfile:

    gem 'resque'

Next, install it with Bundler:
{'fraction_non_alphanumeric': 0.10685589063967442, 'fraction_numerical': 0.0029218407596785976, 'mean_word_length': 4.578579743888242, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6764607', 'n_tokens_mistral': 3003, 'n_tokens_neox': 2789, 'n_words': 1172}