Sha256: 67b7acd95949c89f6fdba4f940da35720257f48e5eba4f39d9825ff30e18f4ab

Contents?: true

Size: 1.71 KB

Versions: 69

Compression:

Stored size: 1.71 KB

Contents

module ForemanInventoryUpload
  module Async
    class QueueForUploadJob < ::ApplicationJob
      def perform(base_folder, report_file, organization_id)
        @base_folder = base_folder
        @report_file = report_file
        logger.debug('Ensuring objects')
        ensure_ouput_folder
        ensure_output_script
        logger.debug("Copying #{report_file} to #{uploads_folder}")
        enqueued_file_name = File.join(uploads_folder, report_file)
        FileUtils.mv(File.join(base_folder, report_file), enqueued_file_name)
        logger.debug("Done copying #{report_file} to #{enqueued_file_name}")

        UploadReportJob.perform_later(enqueued_file_name, organization_id)
      end

      def uploads_folder
        @uploads_folder ||= ForemanInventoryUpload.uploads_folder
      end

      def script_file
        @script_file ||= File.join(uploads_folder, ForemanInventoryUpload.upload_script_file)
      end

      def ensure_ouput_folder
        FileUtils.mkdir_p(uploads_folder)
      end

      def ensure_output_script
        return if File.exist?(script_file)

        script_source = File.join(ForemanRhCloud::Engine.root, 'lib/foreman_inventory_upload/scripts/uploader.sh.erb')

        template_src = Foreman::Renderer::Source::String.new(content: File.read(script_source))
        scope = Foreman::Renderer::Scope::Base.new(
          source: template_src,
          variables: {
            upload_url: ForemanInventoryUpload.upload_url,
          }
        )
        script_source = Foreman::Renderer.render(template_src, scope)
        File.write(script_file, script_source)
        FileUtils.chmod('+x', script_file)
      end

      def logger
        Foreman::Logging.logger('background')
      end
    end
  end
end

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
foreman_rh_cloud-4.0.36 lib/foreman_inventory_upload/async/queue_for_upload_job.rb
foreman_rh_cloud-3.0.33 lib/foreman_inventory_upload/async/queue_for_upload_job.rb
foreman_rh_cloud-4.0.35 lib/foreman_inventory_upload/async/queue_for_upload_job.rb
foreman_rh_cloud-3.0.32 lib/foreman_inventory_upload/async/queue_for_upload_job.rb
foreman_rh_cloud-4.0.32 lib/foreman_inventory_upload/async/queue_for_upload_job.rb
foreman_rh_cloud-4.0.31 lib/foreman_inventory_upload/async/queue_for_upload_job.rb
foreman_rh_cloud-4.0.30 lib/foreman_inventory_upload/async/queue_for_upload_job.rb
foreman_rh_cloud-3.0.29 lib/foreman_inventory_upload/async/queue_for_upload_job.rb
foreman_rh_cloud-4.0.29 lib/foreman_inventory_upload/async/queue_for_upload_job.rb
foreman_rh_cloud-3.0.28 lib/foreman_inventory_upload/async/queue_for_upload_job.rb
foreman_rh_cloud-4.0.27 lib/foreman_inventory_upload/async/queue_for_upload_job.rb
foreman_rh_cloud-3.0.26 lib/foreman_inventory_upload/async/queue_for_upload_job.rb
foreman_rh_cloud-4.0.26 lib/foreman_inventory_upload/async/queue_for_upload_job.rb
foreman_rh_cloud-4.0.25.1 lib/foreman_inventory_upload/async/queue_for_upload_job.rb
foreman_rh_cloud-3.0.25 lib/foreman_inventory_upload/async/queue_for_upload_job.rb
foreman_rh_cloud-4.0.25 lib/foreman_inventory_upload/async/queue_for_upload_job.rb
foreman_rh_cloud-3.0.24.1 lib/foreman_inventory_upload/async/queue_for_upload_job.rb
foreman_rh_cloud-4.0.24.1 lib/foreman_inventory_upload/async/queue_for_upload_job.rb
foreman_rh_cloud-3.0.24 lib/foreman_inventory_upload/async/queue_for_upload_job.rb
foreman_rh_cloud-4.0.24 lib/foreman_inventory_upload/async/queue_for_upload_job.rb