Skip to content

Instantly share code, notes, and snippets.

@fidel
Last active December 12, 2015 07:38
Show Gist options
  • Save fidel/4737791 to your computer and use it in GitHub Desktop.
Save fidel/4737791 to your computer and use it in GitHub Desktop.
Resque
# app/workers/base_task.rb
class BaseTask
def self.perform(*args)
ActiveRecord::Base.verify_active_connections!
self.perform_delegate(*args)
end
def self.perform_delegate(*args) # override this
return args
end
end
# app/workers/do_something.rb
class DoSomething < BaseTask
@queue = :do_something
def self.perform_delegate(id)
obj = ActiveRecordKlass.where(id: id).first
obj.do_something!
end
end
# config/initializers/resque.rb
# Hack to reload code in workers in development mode
unless Rails.application.config.cache_classes
Resque.after_fork do |job|
ActionDispatch::Reloader.cleanup!
ActionDispatch::Reloader.prepare!
end
end
# other resque config stuff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment