1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-10 21:24:20 +01:00
fab-manager/app/workers/availabilities_export_worker.rb

26 lines
794 B
Ruby
Raw Normal View History

# frozen_string_literal: true
# Asynchronously export all the availabilities to an excel sheet
2017-03-02 12:34:28 +01:00
class AvailabilitiesExportWorker
2017-03-02 12:34:16 +01:00
include Sidekiq::Worker
def perform(export_id)
export = Export.find(export_id)
raise SecurityError, 'Not allowed to export' unless export.user.admin?
2017-03-02 12:34:16 +01:00
raise KeyError, 'Wrong worker called' unless export.category == 'availabilities'
2017-03-02 12:34:16 +01:00
2017-03-02 12:34:28 +01:00
service = AvailabilitiesExportService.new
2017-03-02 12:34:16 +01:00
method_name = "export_#{export.export_type}"
return unless %w[index].include?(export.export_type) && service.respond_to?(method_name)
2017-03-02 12:34:16 +01:00
service.public_send(method_name, export)
2017-03-02 12:34:16 +01:00
NotificationCenter.call type: :notify_admin_export_complete,
receiver: export.user,
attached_object: export
2017-03-02 12:34:16 +01:00
end
end