Class: Mensa::ExportJob
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- Mensa::ExportJob
- Defined in:
- app/jobs/mensa/export_job.rb
Overview
Generates the CSV for a Mensa::Export, attaches it to the export’s asset and broadcasts the refreshed export button badge and downloads list so the requesting user sees the finished download appear without reloading.
Instance Method Summary collapse
Instance Method Details
#perform(export) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/jobs/mensa/export_job.rb', line 12 def perform(export) return unless export export.update(status: "processing") Mensa.config.callbacks[:export_started]&.call(export) table = build_table(export) unless table.exportable? finalize(export, status: "failed") return end data, filename, content_type = generate(table, export) export.asset.attach(io: StringIO.new(data), filename: filename, content_type: content_type) finalize(export, status: "completed", filename: filename) Mensa.config.callbacks[:export_complete]&.call(export) rescue => e Mensa.config.logger&.error("Mensa::ExportJob failed for export #{export_id}: #{e.class}: #{e.}") finalize(export, status: "failed") if export raise end |