2016-07-27 11:28:54 +02:00
|
|
|
class StatisticsExportWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
|
|
|
def perform(export_id)
|
|
|
|
export = Export.find(export_id)
|
|
|
|
|
2019-01-14 12:57:31 +01:00
|
|
|
unless export.user.admin?
|
2016-07-27 11:28:54 +02:00
|
|
|
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}"
|
|
|
|
|
2017-03-01 12:56:11 +01:00
|
|
|
if %w(account event machine project subscription training space global).include?(export.export_type) and service.respond_to?(method_name)
|
2016-07-27 11:28:54 +02:00
|
|
|
service.public_send(method_name, export)
|
|
|
|
|
|
|
|
NotificationCenter.call type: :notify_admin_export_complete,
|
|
|
|
receiver: export.user,
|
|
|
|
attached_object: export
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|