1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-10 21:24:20 +01:00
fab-manager/app/workers/statistics_export_worker.rb
Sylvain 4d2f46ca95 [feature] Async statistics export to XLSX
- fix tests due to removal of event_categories
- rake task for generating statistics
2016-07-27 11:28:54 +02:00

28 lines
776 B
Ruby

class StatisticsExportWorker
include Sidekiq::Worker
def perform(export_id)
export = Export.find(export_id)
unless export.user.is_admin?
raise SecurityError, 'Not allowed to export'
end
unless export.category == 'statistics'
raise KeyError, 'Wrong worker called'
end
service = StatisticsExportService.new
method_name = "export_#{export.export_type}"
if %w(account event machine project subscription training global).include?(export.export_type) and service.respond_to?(method_name)
service.public_send(method_name, export)
NotificationCenter.call type: :notify_admin_export_complete,
receiver: export.user,
attached_object: export
end
end
end