Class: Marty::JobController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/marty/job_controller.rb

Instance Method Summary collapse

Instance Method Details

#downloadObject



2
3
4
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
# File 'app/controllers/marty/job_controller.rb', line 2

def download
  job_id = params['job_id']

  promise = Marty::Promise.find_by_id(job_id)

  if promise
    format = promise.cformat

    # Force result so finalized object is built
    data = promise.result(true)

    # somewhat hacky: if result has "result" key, it's used as the
    # content.
    data = data['result'] || data
    title = promise.title
  else
    format = 'json'
    data = { error: "Job not found: #{job_id}" }
    title = 'error'
  end

  res, type, disposition, filename =
    Marty::ContentHandler.export(data, format, title)

  send_data(res,
            type:        type,
            filename:    filename,
            disposition: disposition,
           )
end