• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / tigerdata-app / 0007d2c6-41b5-42ed-97a7-b69a0324145b

16 Dec 2024 08:30PM UTC coverage: 83.364% (-0.07%) from 83.431%
0007d2c6-41b5-42ed-97a7-b69a0324145b

Pull #1135

circleci

carolyncole
Allowing the user mediaflux session to be passed to the inventory job
Pull Request #1135: Allowing the user mediaflux session to be passed to the inventory job

4 of 4 branches covered (100.0%)

3 of 3 new or added lines in 2 files covered. (100.0%)

2 existing lines in 1 file now uncovered.

2275 of 2729 relevant lines covered (83.36%)

370.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.55
/app/jobs/file_inventory_job.rb
1
# frozen_string_literal: true
2
class FileInventoryJob < ApplicationJob
1✔
3
  # Create the FileInventoryRequest as soon as the job is created, not when it is performed
4
  before_enqueue do |job|
1✔
5
    project = Project.find(job.arguments.first[:project_id])
2✔
6
    FileInventoryRequest.create(user_id: job.arguments.first[:user_id], project_id: job.arguments.first[:project_id], job_id: @job_id, state: UserRequest::PENDING,
2✔
7
                                request_details: { project_title: project.title })
8
  end
9

10
  # This is required because the before_enqueue does not get called when perform_now is run on a job
11
  # We include both before_perform and before_enqueue so perform_now and perform_later will work as desired
12
  before_perform do |job|
1✔
13
    project = Project.find(job.arguments.first[:project_id])
11✔
14
    inventory_request = FileInventoryRequest.find_by(user_id: job.arguments.first[:user_id], project_id: job.arguments.first[:project_id], job_id: @job_id)
11✔
15
    if inventory_request.blank?
11✔
16
      FileInventoryRequest.create(user_id: job.arguments.first[:user_id], project_id: job.arguments.first[:project_id], job_id: @job_id, state: UserRequest::PENDING,
10✔
17
                                  request_details: { project_title: project.title })
18
    end
19
  end
20

21
  def perform(user_id:, project_id:, mediaflux_session:)
1✔
22
    project = Project.find(project_id)
11✔
23
    raise "Invalid project id #{project_id} for job #{job_id}" if project.nil?
11✔
24
    user = User.find(user_id)
11✔
25
    raise "Invalid user id #{user_id} for job #{job_id}" if user.nil?
10✔
26
    Rails.logger.debug inspect
10✔
27

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

31
    # Queries Mediaflux for the file list and saves it to a CSV file.
32
    filename = filename_for_export
10✔
33
    Rails.logger.info "Exporting file list to #{filename} for project #{project_id}"
10✔
34
    project.file_list_to_file(session_id: mediaflux_session, filename: filename)
10✔
35
    Rails.logger.info "Export file generated #{filename} for project #{project_id}"
10✔
36

37
    # Make the FileInventoryRequest object
38
    inventory_request = FileInventoryRequest.find_by(user_id: user.id, project_id: project.id, job_id: @job_id)
10✔
39
    inventory_request.update(state: UserRequest::COMPLETED, request_details: { output_file: filename, project_title: project.title },
10✔
40
                             completion_time: Time.current.in_time_zone("America/New_York"))
41
    inventory_request
10✔
42
  end
43

44
  private
1✔
45

46
    def mediaflux_session
1✔
UNCOV
47
      logon_request = Mediaflux::LogonRequest.new
×
UNCOV
48
      logon_request.session_token
×
49
    end
50

51
    def filename_for_export
1✔
52
      raise "Shared location is not configured" if Rails.configuration.mediaflux["shared_files_location"].blank?
10✔
53
      pathname = Pathname.new(Rails.configuration.mediaflux["shared_files_location"])
10✔
54
      pathname.join("#{job_id}.csv").to_s
10✔
55
    end
56
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc