Class: TResque::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/tresque/registry.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_key) ⇒ Registry

Returns a new instance of Registry.



85
86
87
# File 'lib/tresque/registry.rb', line 85

def initialize(app_key)
  @app_key = Util.normalize(app_key)
end

Instance Attribute Details

#app_keyObject (readonly)

Returns the value of attribute app_key.



84
85
86
# File 'lib/tresque/registry.rb', line 84

def app_key
  @app_key
end

Class Method Details

.class_hashObject



10
11
12
# File 'lib/tresque/registry.rb', line 10

def class_hash
  @class_hash ||= {}
end

.class_listObject



18
19
20
# File 'lib/tresque/registry.rb', line 18

def class_list
  class_hash.keys
end

.default_weightObject



6
7
8
# File 'lib/tresque/registry.rb', line 6

def default_weight
  100
end

.queue(queue_name, weight = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/tresque/registry.rb', line 28

def queue(queue_name, weight=nil)
  queue_name = queue_name.to_s
  if weight
    # take higher weight
    if !queue_hash[queue_name] || weight > queue_hash[queue_name]
      queue_hash[queue_name] = weight
    end
  else
    queue_hash[queue_name] ||= false
  end
end

.queue_hashObject



14
15
16
# File 'lib/tresque/registry.rb', line 14

def queue_hash
  @queue_hash ||= {}
end

.queuesObject

called to know what queues to set



49
50
51
52
53
# File 'lib/tresque/registry.rb', line 49

def queues
  register_classes
  register_bus
  sorted_queues
end

.weight(key) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/tresque/registry.rb', line 40

def weight(key)
  if !self.queue_hash[key]
    self.default_weight
  else
    self.queue_hash[key]
  end
end

.worker(klass) ⇒ Object



22
23
24
25
26
# File 'lib/tresque/registry.rb', line 22

def worker(klass)
  klass = klass.name if klass.is_a?(Class)
  klass = klass.to_s
  class_hash[klass] = 1
end

Instance Method Details

#queue(name, weight = nil) ⇒ Object



89
90
91
92
# File 'lib/tresque/registry.rb', line 89

def queue(name, weight=nil)
  queue_name = "#{app_key}_#{name}"
  ::TResque::Registry.queue(queue_name, weight)
end