Skip to content

Instantly share code, notes, and snippets.

@foca
Created July 22, 2011 18:29
Show Gist options
  • Save foca/1100060 to your computer and use it in GitHub Desktop.
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.
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)
@foca
Copy link
Author

foca commented Jul 22, 2011

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment