Class: Steve::Interface

Inherits:
Object
  • Object
show all
Defined in:
lib/steve/interface.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



5
6
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
40
41
42
43
44
45
# File 'lib/steve/interface.rb', line 5

def call(env)
  @req = Rack::Request.new(env)
  case env['PATH_INFO'].to_s
  when '/', ''
    [200, {'Content-type' => 'text/html'}, [haml(:index)]]
  when /failed/
    @jobs = paginate(Steve::ArchivedJob.failed.asc, :page => @req.params['page'], :per_page => 50)
    [200, {'Content-type' => 'text/html'}, [haml(:failed)]]
  when /completed/
    @jobs = paginate(Steve::ArchivedJob.completed.asc, :page => @req.params['page'], :per_page => 50)
    [200, {'Content-type' => 'text/html'}, [haml(:completed)]]
  when /archived\/object/
    @jobs = Steve::ArchivedJob.where(:associated_object_type => @req.params['type'], :associated_object_id => @req.params['id']).order('created_at desc').limit(25)
    [200, {'Content-type' => 'text/html'}, [haml(:object)]]
  when /archived\/view/
    @job = Steve::ArchivedJob.find(@req.params['id'])
    [200, {'Content-type' => 'text/html'}, [haml(:view)]]
  when /object/
    @jobs = Steve::QueuedJob.where(:associated_object_type => @req.params['type'], :associated_object_id => @req.params['id']).order('created_at desc').limit(25)
    [200, {'Content-type' => 'text/html'}, [haml(:object)]]
  when /view/
    @job = Steve::QueuedJob.find(@req.params['id'])
    [200, {'Content-type' => 'text/html'}, [haml(:view)]]
  when /retry/
    @archived_job = Steve::ArchivedJob.find(@req.params['id'])
    if @archived_job.retry!
      [302, {'Location' => '/jobs/?status=retried'}]
    else
      [302, {'Location' => '/jobs/?status=retryfailed'}]
    end

  else
    path = static_path(env['PATH_INFO'])
    if File.exist?(path)
      [200, {}, [File.read(path)]]
    else
      [404, {'Content-type' => 'text/plain'}, ["Not found"]]
    end

  end
end