Created
July 22, 2011 18:29
-
-
Save foca/1100060 to your computer and use it in GitHub Desktop.
I don't really care for running Resque in dev or test environments.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Job | |
LAZY_ENVIRONMENTS = %w(development test) | |
# Add a job to the queue. If we're currently running in any of the | |
# environments listed in +LAZY_ENVIRONMENTS+ then it automatically performs | |
# the job. | |
def self.enqueue(*args) | |
if LAZY_ENVIRONMENTS.include? Rails.env | |
Rails.logger.debug "Performing job instead of enqueuing: #{name}" | |
perform(*args) | |
else | |
Resque.enqueue self, *args | |
end | |
end | |
end | |
class SomeOtherJob < Job | |
@queue = :blah | |
def self.perform(*args) | |
p args | |
end | |
end | |
SomeOtherJob.enqueue(1, 2, 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This of course can mean some job will result in a timeout when you have jobs that process A LOT of things, but it's acceptable for 99.99% of the cases :)