Class: Importo::ExportJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/importo/export_job.rb

Constant Summary collapse

CONTENT_TYPE =
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

Instance Method Summary collapse

Instance Method Details

#perform(import_id, kind) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/jobs/importo/export_job.rb', line 5

def perform(import_id, kind)
  import = Import.find(import_id)
  import.start_export!

  importer = import.importer
  file_kind = kind.to_sym
  file = importer.public_send(:"#{file_kind}_file")

  filename = importer.file_name(file_kind)
  import.result.attach(io: file, filename: filename, content_type: CONTENT_TYPE)
  import.update!(result_message: filename)
  import.complete_export!
rescue => error
  import&.update!(result_message: "Exception: #{error.message}")
  import&.failure!
end