# frozen_string_literal: true

module VulnerabilityExports
  class ExportWorker
    include ApplicationWorker
    include ::Gitlab::ExclusiveLeaseHelpers

    sidekiq_options dead: false

    feature_category :vulnerability_management
    worker_resource_boundary :cpu

    idempotent!

    sidekiq_retries_exhausted do |job|
      Vulnerabilities::Export.find_by_id(job['args'].last).failed!
    end

    def perform(_exportable_id = nil, vulnerability_export_id) # rubocop:disable Style/OptionalArguments
      vulnerability_export = Vulnerabilities::Export.find_by_id(vulnerability_export_id)
      return unless vulnerability_export

      ExportService.export(vulnerability_export)
    end
  end
end
