Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated README to match current code #49

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,19 @@ Note: If your error messages are long, consider changing last_error field to a :

h2. Usage

Jobs are simple ruby objects with a method called perform. Any object which responds to perform can be stuffed into the jobs table.
Job objects are serialized to yaml so that they can later be resurrected by the job runner.
If you are delaying a single method call, you can queue up that call simply be prefixing it with @delay@. (@send_later@ is deprecated) E.g.,

<pre><code>
UserMailer.send_welcome_email(user)
BatchImporter.new(Shop.find(1)).import_massive_csv(massive_csv)
</code></pre>
becomes
<pre><code>
serMailer.delay.send_welcome_email(user)
BatchImporter.new(Shop.find(1)).delay.import_massive_csv(massive_csv)
</code></pre>

You can make more complicated jobs by creating a simple Ruby object with a method called @perform@. Any object which responds to @perform@ can be stuffed into the jobs table. Job objects are serialized to YAML so that they can later be resurrected by the job runner. E.g.,

<pre><code>
class NewsletterJob < Struct.new(:text, :emails)
Expand All @@ -75,14 +86,7 @@ Job objects are serialized to yaml so that they can later be resurrected by the
Delayed::Job.enqueue NewsletterJob.new('lorem ipsum...', Customers.find(:all).collect(&:email))
</code></pre>

There is also a second way to get jobs in the queue: send_later.

<pre><code>
BatchImporter.new(Shop.find(1)).send_later(:import_massive_csv, massive_csv)
</code></pre>

This will simply create a @Delayed::PerformableMethod@ job in the jobs table which serializes all the parameters you pass to it. There are some special smarts for active record objects
which are stored as their text representation and loaded from the database fresh when the job is actually run later.
When you use the @delay@ method, it simply creates a @Delayed::PerformableMethod@ job in the jobs table which serializes all the parameters you pass to it. There are some special smarts for active record objects which are stored as their text representation and loaded from the database fresh when the job is actually run later.


h2. Running the jobs
Expand All @@ -106,7 +110,7 @@ run multiple workers on per computer, but you must give each one a unique name:
worker = Delayed::Worker.new
worker.name = 'worker-' + n.to_s
worker.start
end
end
</code></pre>

Keep in mind that each worker will check the database at least every 5 seconds.
Expand All @@ -119,6 +123,8 @@ You can invoke @rake jobs:clear@ to delete all jobs in the queue.

h3. Changes

* 2.0: TO WRITE

* 1.7.0: Added failed_at column which can optionally be set after a certain amount of failed job attempts. By default failed job attempts are destroyed after about a month.

* 1.6.0: Renamed locked_until to locked_at. We now store when we start a given job instead of how long it will be locked by the worker. This allows us to get a reading on how long a job took to execute.
Expand Down