Class: FileInventoryJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/file_inventory_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(user_id:, project_id:, mediaflux_session:) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/jobs/file_inventory_job.rb', line 21

def perform(user_id:, project_id:, mediaflux_session:)
  project = Project.find(project_id)
  raise "Invalid project id #{project_id} for job #{job_id}" if project.nil?
  user = User.find(user_id)
  raise "Invalid user id #{user_id} for job #{job_id}" if user.nil?
  Rails.logger.debug inspect

  # set the mediaflux session to the one the user created, do not just utilize the system one
  user.mediaflux_from_session({ mediaflux_session: })

  # Queries Mediaflux for the file list and saves it to a CSV file.
  filename = filename_for_export
  Rails.logger.info "Exporting file list to #{filename} for project #{project_id} (session: #{mediaflux_session})"
  project.file_list_to_file(session_id: mediaflux_session, filename: filename)
  Rails.logger.info "Export file generated #{filename} for project #{project_id} (session: #{mediaflux_session})"

  # Update the job record as completed
  update_inventory_request(user_id: user.id, project: project, job_id: @job_id, filename: filename)
end