Class: ResqueAsync::Enqueuers::ClassEnqueuer

Inherits:
Object
  • Object
show all
Defined in:
lib/resque-async/enqueuers.rb

Direct Known Subclasses

ActiveRecordEnqueuer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host_class, priority) ⇒ ClassEnqueuer

Returns a new instance of ClassEnqueuer.



8
9
10
11
# File 'lib/resque-async/enqueuers.rb', line 8

def initialize(host_class, priority)
  @host_class = host_class
  @priority = priority
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(methId, *args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/resque-async/enqueuers.rb', line 13

def method_missing(methId, *args)
  # call super unless the host responds to the method
  return super unless @host_class.respond_to?(methId.id2name.to_sym)

  case @priority
    when Class
      worker = @priority
    when :high
      worker = Workers::HighPriorityClassMethod
    when :medium
      worker = Workers::MediumPriorityClassMethod
    when :low
      worker = Workers::LowPriorityClassMethod
    else
      raise StandardError('Unknown priority')
  end
  # enqueue
  Resque.enqueue(worker, @host_class.name, methId.id2name, args)
end

Instance Attribute Details

#host_classObject (readonly)

Returns the value of attribute host_class.



7
8
9
# File 'lib/resque-async/enqueuers.rb', line 7

def host_class
  @host_class
end

#priorityObject (readonly)

Returns the value of attribute priority.



7
8
9
# File 'lib/resque-async/enqueuers.rb', line 7

def priority
  @priority
end