Class: Requeus::Impl

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/requeus/impl.rb

Instance Method Summary collapse

Instance Method Details

#blob_sequenceObject



39
40
41
42
43
44
# File 'lib/requeus/impl.rb', line 39

def blob_sequence
  @blob_sequence ||= config['blob']['sequence'].split.map do |name|
    conf = @config['blob'][name]
    Requeus::BlobStore.new name, conf
  end
end

#configObject



20
21
22
# File 'lib/requeus/impl.rb', line 20

def config
  @config ||= YAML.load_file(@config_path)[ENV['REQUEUS_ENV'] || ENV['RAILS_ENV'] || 'development']
end

#config_path=(path) ⇒ Object



16
17
18
# File 'lib/requeus/impl.rb', line 16

def config_path= path
  @config_path = path
end

#queuesObject



24
25
26
27
28
29
30
# File 'lib/requeus/impl.rb', line 24

def queues
  @queues ||= {}.tap do |queues|
    config['queues'].each do |name, conf|
      queues[name] = Requeus::Queue.new conf
    end
  end
end

#request(queue, method, path, params, headers, force_endpoint) ⇒ Object



7
8
9
10
# File 'lib/requeus/impl.rb', line 7

def request queue, method, path, params, headers, force_endpoint
  r = Requeus::Request.new(method, path, params, headers, force_endpoint).to_json
  server_sequence.any? {|q| q.put(queues[queue].name, r)}
end

#server_sequenceObject



32
33
34
35
36
37
# File 'lib/requeus/impl.rb', line 32

def server_sequence
  @server_sequence ||= config['servers']['sequence'].split.map do |name|
    conf = @config['servers'][name]
    Requeus::Server.new name, conf
  end
end

#start_workersObject



12
13
14
# File 'lib/requeus/impl.rb', line 12

def start_workers
  queues.values.map {|q| q.start_workers}.flatten.each(&:join)
end