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
40
41
42
# 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}"
  project.file_list_to_file(session_id: mediaflux_session, filename: filename)
  Rails.logger.info "Export file generated #{filename} for project #{project_id}"
  # Make the FileInventoryRequest object
  inventory_request = FileInventoryRequest.find_by(user_id: user.id, project_id: project.id, job_id: @job_id)
  request_details = { output_file: filename, project_title: project.title, file_size: File.size(filename) }
  inventory_request.update(state: UserRequest::COMPLETED, request_details: request_details,
                           completion_time: Time.current.in_time_zone("America/New_York"))
  inventory_request
end