Class: ForemanInventoryUpload::Async::QueueForUploadJob

Inherits:
Actions::EntryAction
  • Object
show all
Defined in:
lib/foreman_inventory_upload/async/queue_for_upload_job.rb

Instance Method Summary collapse

Instance Method Details

#base_folderObject



32
33
34
# File 'lib/foreman_inventory_upload/async/queue_for_upload_job.rb', line 32

def base_folder
  input[:base_folder]
end

#ensure_ouput_folderObject



24
25
26
# File 'lib/foreman_inventory_upload/async/queue_for_upload_job.rb', line 24

def ensure_ouput_folder
  FileUtils.mkdir_p(uploads_folder)
end

#loggerObject



28
29
30
# File 'lib/foreman_inventory_upload/async/queue_for_upload_job.rb', line 28

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

#plan(base_folder, report_file, organization_id) ⇒ 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)
  enqueue_task = plan_self(base_folder: base_folder, report_file: report_file)
  plan_upload_report(enqueue_task.output[:enqueued_file_name], organization_id)
end

#plan_upload_report(enqueued_file_name, organization_id) ⇒ Object



40
41
42
# File 'lib/foreman_inventory_upload/async/queue_for_upload_job.rb', line 40

def plan_upload_report(enqueued_file_name, organization_id)
  plan_action(UploadReportDirectJob, enqueued_file_name, organization_id)
end

#report_fileObject



36
37
38
# File 'lib/foreman_inventory_upload/async/queue_for_upload_job.rb', line 36

def report_file
  input[:report_file]
end

#runObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/foreman_inventory_upload/async/queue_for_upload_job.rb', line 9

def run
  logger.debug('Ensuring objects')
  ensure_ouput_folder
  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

#uploads_folderObject



20
21
22
# File 'lib/foreman_inventory_upload/async/queue_for_upload_job.rb', line 20

def uploads_folder
  @uploads_folder ||= ForemanInventoryUpload.uploads_folder
end