2022-10-24 17:39:16 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# asynchronously export the statistics to an excel file and send the result by email
|
2016-07-27 11:28:54 +02:00
|
|
|
class StatisticsExportWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
|
|
|
def perform(export_id)
|
|
|
|
export = Export.find(export_id)
|
|
|
|
|
2022-10-24 17:39:16 +02:00
|
|
|
raise SecurityError, 'Not allowed to export' unless export.user.admin?
|
2016-07-27 11:28:54 +02:00
|
|
|
|
2022-10-24 17:39:16 +02:00
|
|
|
raise KeyError, 'Wrong worker called' unless export.category == 'statistics'
|
2016-07-27 11:28:54 +02:00
|
|
|
|
|
|
|
service = StatisticsExportService.new
|
|
|
|
method_name = "export_#{export.export_type}"
|
|
|
|
|
2023-02-20 15:37:51 +01:00
|
|
|
unless %w[account event machine project subscription training space order global].include?(export.export_type) &&
|
2022-10-24 17:39:16 +02:00
|
|
|
service.respond_to?(method_name)
|
2023-02-20 15:37:51 +01:00
|
|
|
raise TypeError("Invalid statistics export type #{export.export_type}")
|
2016-07-27 11:28:54 +02:00
|
|
|
end
|
|
|
|
|
2022-10-24 17:39:16 +02:00
|
|
|
service.public_send(method_name, export)
|
|
|
|
|
|
|
|
NotificationCenter.call type: :notify_admin_export_complete,
|
|
|
|
receiver: export.user,
|
|
|
|
attached_object: export
|
2016-07-27 11:28:54 +02:00
|
|
|
end
|
|
|
|
end
|