Module: ResqueSerial::Server

Defined in:
lib/resque-serial/server.rb

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



7
8
9
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
# File 'lib/resque-serial/server.rb', line 7

def self.registered(app)

  app.class_eval do

    helpers do
      def render_view(filename)
        erb File.read(File.join(File.dirname(__FILE__), 'server', 'views', "#{filename}.erb"))
      end
    end

    get '/serials' do
      @serials = Redis.current.keys 'resque:syncjobs:*'
      @serials.map! { |serial| { name: serial.split(':').last, size: Redis.current.llen(serial) } }
      render_view :serials
    end

    get '/serials/:id' do
      @serial_name = params[:id]
      serial = "resque:syncjobs:#{@serial_name}"
      @count = Redis.current.llen serial
      @jobs = Redis.current.lrange serial, 0, @count

      @jobs.map! { |job| YAML.load job }
      render_view :serial
    end

    post '/serials/:id/remove' do
      serial = "resque:syncjobs:#{params[:id]}"
      Redis.current.del serial
      redirect u(:serials)
    end
  end
end