https://github.com/markbates/dj_remixes
Enhancements and improvements for Delayed Job 2.x
https://github.com/markbates/dj_remixes
Last synced: about 1 year ago
JSON representation
Enhancements and improvements for Delayed Job 2.x
- Host: GitHub
- URL: https://github.com/markbates/dj_remixes
- Owner: markbates
- License: mit
- Created: 2010-06-14T19:34:15.000Z (about 16 years ago)
- Default Branch: master
- Last Pushed: 2011-08-26T15:33:42.000Z (almost 15 years ago)
- Last Synced: 2025-03-30T16:46:28.625Z (about 1 year ago)
- Language: Ruby
- Homepage: http://www.metabates.com
- Size: 282 KB
- Stars: 42
- Watchers: 1
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.textile
- License: LICENSE
Awesome Lists containing this project
README
h1. DJ Remixes
A boat load of incredibly useful 'plugins' for Delayed::Job! DJ is a wonderful project and is incredibly useful, however it can be even more useful with just a few extras added in.
h2. The Extras
* A proper 'Worker' class: DJ::Worker that accepts attributes.
* Callbacks
* Airbrake (Hoptoad) support, if using Airbrake.
* Priority settings
* Automatic re-enqueueing
* Better scheduling
* Unique jobs.
* more ...
These are a few of the extras for DJ that are included here.
h2. Installation
In your Gemfile add the following:
gem "delayed_job", "2.1.4"
gem "dj_remixes"
Then install the gems:
$ bundle install
Create a migration to add the required dj_remixes fields to the delayed_job table:
class AddDjRemixesColumns < ActiveRecord::Migration
def self.up
add_column :delayed_jobs, :worker_class_name, :string
add_column :delayed_jobs, :started_at, :datetime
add_column :delayed_jobs, :finished_at, :datetime
end
def self.down
remove_column :delayed_jobs, :worker_class_name
remove_column :delayed_jobs, :started_at
remove_column :delayed_jobs, :finished_at
end
end
h2. Using
h3. Basic Worker
class FooWorker < DJ::Worker
def perform
# do work
end
end
FooWorker.enqueue
h3. Unique Worker
Tell DJ to only allow one of this worker at a given time.
# We only want to charge the card once!
class PurchaseWorker < DJ::Worker
is_unique
def perform
# charge the credit card...
end
end
If the worker has an id attribute that then will be used in conjunction with the class name of the worker to form the unique key.
h3. Priority
Tell DJ to run this worker with a higher priority than others.
class FooWorker < DJ::Worker
priority :high
def perform
# do work
end
end
FooWorker.enqueue
h3. Re-Enqueueing
Tell DJ to re-enqueue this worker after it has successfully completely. *NOTE*: This will actually create a new DJ object in the database, not reuse the same one.
# Run every 30 days and charge a credit card.
class SubscriptionWorker < DJ::Worker
re_enqueue
def run_at
30.days.from_now
end
def perform
# charge the credit card...
end
end
h3. Attributes
The DJ::Worker class can accept attributes, similar to the way an ActiveRecord model can.
class FooWorker < DJ::Worker
priority :high
def perform
# do work
puts self.id # => 1
puts self.person # => 'Mark Bates'
end
end
worker = FooWorker.new(:id => 1, :person => 'Mark Bates')
worker.enqueue!
h2. Contributors
* Mark Bates
* Stuart Garner
* Brent Kirby
* Luke Pearce
* Lars Pindrake