Class: ForemanInventoryUpload::Async::QueueForUploadJob
- Inherits:
-
Actions::EntryAction
- Object
- Actions::EntryAction
- ForemanInventoryUpload::Async::QueueForUploadJob
- Defined in:
- lib/foreman_inventory_upload/async/queue_for_upload_job.rb
Instance Method Summary collapse
- #base_folder ⇒ Object
- #ensure_ouput_folder ⇒ Object
- #ensure_output_script ⇒ Object
- #logger ⇒ Object
- #plan(base_folder, report_file, organization_id, disconnected) ⇒ Object
- #plan_upload_report(enqueued_file_name, organization_id) ⇒ Object
- #report_file ⇒ Object
- #run ⇒ Object
- #script_file ⇒ Object
- #uploads_folder ⇒ Object
Instance Method Details
#base_folder ⇒ Object
54 55 56 |
# File 'lib/foreman_inventory_upload/async/queue_for_upload_job.rb', line 54 def base_folder input[:base_folder] end |
#ensure_ouput_folder ⇒ Object
29 30 31 |
# File 'lib/foreman_inventory_upload/async/queue_for_upload_job.rb', line 29 def ensure_ouput_folder FileUtils.mkdir_p(uploads_folder) end |
#ensure_output_script ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/foreman_inventory_upload/async/queue_for_upload_job.rb', line 33 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 |
#logger ⇒ Object
50 51 52 |
# File 'lib/foreman_inventory_upload/async/queue_for_upload_job.rb', line 50 def logger Foreman::Logging.logger('background') end |
#plan(base_folder, report_file, organization_id, disconnected) ⇒ Object
4 5 6 7 |
# File 'lib/foreman_inventory_upload/async/queue_for_upload_job.rb', line 4 def plan(base_folder, report_file, organization_id, disconnected) enqueue_task = plan_self(base_folder: base_folder, report_file: report_file) plan_upload_report(enqueue_task.output[:enqueued_file_name], organization_id) unless disconnected end |
#plan_upload_report(enqueued_file_name, organization_id) ⇒ Object
62 63 64 |
# File 'lib/foreman_inventory_upload/async/queue_for_upload_job.rb', line 62 def plan_upload_report(enqueued_file_name, organization_id) plan_action(UploadReportJob, enqueued_file_name, organization_id) end |
#report_file ⇒ Object
58 59 60 |
# File 'lib/foreman_inventory_upload/async/queue_for_upload_job.rb', line 58 def report_file input[:report_file] end |
#run ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/foreman_inventory_upload/async/queue_for_upload_job.rb', line 9 def run 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}") output[:enqueued_file_name] = enqueued_file_name end |
#script_file ⇒ Object
25 26 27 |
# File 'lib/foreman_inventory_upload/async/queue_for_upload_job.rb', line 25 def script_file @script_file ||= File.join(uploads_folder, ForemanInventoryUpload.upload_script_file) end |
#uploads_folder ⇒ Object
21 22 23 |
# File 'lib/foreman_inventory_upload/async/queue_for_upload_job.rb', line 21 def uploads_folder @uploads_folder ||= ForemanInventoryUpload.uploads_folder end |