Class: FreeMessageQueue::AdminInterface
- Inherits:
-
Object
- Object
- FreeMessageQueue::AdminInterface
- Defined in:
- lib/fmq/admin.rb
Overview
This class is dedicated to the AJAX based admin interface.
Constant Summary collapse
- WRONG_METHOD =
rack response for bad requests
[400, {"CONTENT-TYPE" => "text/plain", "ERROR" => "Wrong http Method"}, ""]
- OK =
rack response for good requests
[200, {"CONTENT-TYPE" => "text/plain"}, ["ok"]]
Instance Method Summary collapse
-
#call(env) ⇒ Object
handle all requests.
-
#initialize(queue_manager) ⇒ AdminInterface
constructor
create the admin interface for the passed QueueManager.
Constructor Details
#initialize(queue_manager) ⇒ AdminInterface
create the admin interface for the passed QueueManager
29 30 31 32 |
# File 'lib/fmq/admin.rb', line 29 def initialize(queue_manager) @manager = queue_manager @log = FreeMessageQueue.logger end |
Instance Method Details
#call(env) ⇒ Object
handle all requests
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fmq/admin.rb', line 35 def call(env) begin request = Rack::Request.new(env) @log.debug "[AdminInterface] ENV: #{env.inspect}" if request.get? then @log.info "[AdminInterface] list queues" # ======= LIST QUEUES queues_code = [] @manager.queues.each do |queue_name| queues_code << queue_to_json(queue_name) end return [200, {"CONTENT-TYPE" => "application/json"}, ["[%s]" % queues_code.join(","), ]] elsif request.post? then if request["_method"] == "delete" then # ======= DELETE QUEUE @log.info "[AdminInterface] delete queue" @manager.delete_queue(request["path"]) return OK elsif request["_method"] == "create" # ======= CREATE QUEUE @log.info "[AdminInterface] create queue" @manager.setup_queue(request["path"], request["queue_class"]) do |q| q. = request["max_messages"].to_i q.max_size = str_bytes request["max_size"] request.params.each { |k,v| q.send("#{k[3..-1]}=", v) if k.match(/^qm_/) } end return OK else return WRONG_METHOD end else return WRONG_METHOD end rescue QueueManagerException => ex return [400, {"CONTENT-TYPE" => "text/plain", "ERROR" => ex.}, [ex.]] end end |