Class: Anisoptera::AsyncEndpoint

Inherits:
Object
  • Object
show all
Includes:
Endpoint
Defined in:
lib/anisoptera/async_endpoint.rb

Constant Summary collapse

AsyncResponse =

This is a template async response.

[-1, {}, []].freeze
STATUSES =
{
  0   => 200,
  1   => 500,
  255 => 200 # exit status represented differently when running tests in editor
}

Instance Method Summary collapse

Methods included from Endpoint

factory, #initialize

Instance Method Details

#call(env) ⇒ Object



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
# File 'lib/anisoptera/async_endpoint.rb', line 19

def call(env)
  response = Thin::AsyncResponse.new(env)
  
  params = routing_params(env)
  
  begin
    job = Anisoptera::Commander.new( @config.base_path, @config.convert_command )
    convert = @handler.call(job, params)
    response.headers.update(update_headers(convert))
    
    if !job.check_file
      response.headers['X-Error'] = 'Image not found'  
      handle_error error_status(404), response, convert
    else
      handle_success response, convert
    end
  rescue => boom
    response.headers['X-Error'] = boom.message
    response.headers.update(update_headers)
    @config.on_error.call(boom, params, env) if @config.on_error
    handle_error(error_status(500), response)
  end

  response.finish
end