Class: QueueingProxy::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/queueing_proxy/dsl.rb

Defined Under Namespace

Classes: Backend

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ DSL

Returns a new instance of DSL.



34
35
36
37
# File 'lib/queueing_proxy/dsl.rb', line 34

def initialize(&block)
  @logger = Logger.new($stdout)
  instance_eval(&block) if block
end

Instance Method Details

#from(host, port = 80, &block) ⇒ Object



44
45
46
47
# File 'lib/queueing_proxy/dsl.rb', line 44

def from(host, port=80, &block)
  frontends << [host, port]
  self
end

#logger(logger) ⇒ Object



49
50
51
52
# File 'lib/queueing_proxy/dsl.rb', line 49

def logger(logger)
  @logger = logger
  self
end

#runObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/queueing_proxy/dsl.rb', line 54

def run
  unless EM.reactor_running?
    EM.run{ run }
  else
    # Setup multiple backends
    backends.each {|b|
      b.logger @logger
      b.workers.each(&:run)
    }
    frontends.each do |host, port|
      Frontend.new(@logger, host, port, backends).run
    end
  end
end

#to(host, port = 80, &block) ⇒ Object



39
40
41
42
# File 'lib/queueing_proxy/dsl.rb', line 39

def to(host, port=80, &block)
  backends << Backend.new(host, port, &block)
  self
end