Skip to content

Instantly share code, notes, and snippets.

@shio-phys
Created October 19, 2015 07:23
Show Gist options
  • Save shio-phys/961af7a766bc9d245cd6 to your computer and use it in GitHub Desktop.
Save shio-phys/961af7a766bc9d245cd6 to your computer and use it in GitHub Desktop.
module Crawler
class DomainSpecificWorker
include Sidekiq::Worker
def self.domainify(domain_id)
klass_name = "#{self.name.split('::').last}_#{domain_id}"
unless Crawler.const_defined?(klass_name)
Crawler.const_set(klass_name.to_sym, self.clone)
klass = Crawler.const_get(klass_name.to_sym)
queue = klass.class_variable_get(:@@queue).to_s + "-#{domain_id}"
klass.sidekiq_options(queue: queue.to_sym)
klass.class_variable_set(:@@queue, queue)
end
Crawler.const_get(klass_name.to_sym)
end
end
class HogeWorker < DomainSpecificWorker
@@queue = :hoge
def perform(pamram)
# do something
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment