Module: Resque::Plugins::DynamicQueues::Server

Defined in:
lib/resque/plugins/dynamic_queues/server.rb

Constant Summary collapse

VIEW_PATH =
File.join(File.dirname(__FILE__), 'server', 'views')

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/resque/plugins/dynamic_queues/server.rb', line 10

def self.registered(app)
  app.get "/dynamicqueues" do
    @queues = []
    dqueues = Resque.get_dynamic_queues
    dqueues.each do |k, v|
      view_data = {
          'name' => k,
          'value' => Array(v).join(", "),
          'expanded' => Resque::Worker.new("@#{k}").queues.join(", ")
      }
      @queues << view_data
    end
    
    @queues.sort! do |a, b|
      an = a['name']
      bn = b['name']
      if an == 'default'
        1
      elsif bn == 'default'
        -1
      else
        an <=> bn
      end
    end
    
    dynamicqueues_view :queues
  end

  app.post "/dynamicqueues" do
    dynamic_queues = Array(params['queues'])
    queues = {}
    dynamic_queues.each do |queue|
      key = queue['name']
      values = queue['value'].to_s.split(',').collect{|q| q.gsub(/\s/, '') }
      queues[key] = values
    end
    Resque.set_dynamic_queues(queues)
    redirect "/dynamicqueues"
  end

  app.helpers do
    def dynamicqueues_view(filename, options = {}, locals = {})
      erb(File.read(File.join(::Resque::Plugins::DynamicQueues::Server::VIEW_PATH, "#{filename}.erb")), options, locals)
    end
  end

  app.tabs << "DynamicQueues"
end