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

pulibrary / tigerdata-app / 2019cefc-a8e6-4859-80c7-47af78cd7e4c

07 Nov 2025 06:12PM UTC coverage: 88.239% (-3.1%) from 91.357%
2019cefc-a8e6-4859-80c7-47af78cd7e4c

Pull #2163

circleci

web-flow
Merge branch 'main' into 2157-project-list-error
Pull Request #2163: Logs Mediaflux errors when fetching the project list

8 of 8 new or added lines in 1 file covered. (100.0%)

498 existing lines in 29 files now uncovered.

2761 of 3129 relevant lines covered (88.24%)

488.86 hits per line

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

72.92
/app/jobs/file_inventory_job.rb
1
# frozen_string_literal: true
UNCOV
2
class FileInventoryJob < ApplicationJob
2✔
3
  # Create the FileInventoryRequest as soon as the job is created, not when it is performed
UNCOV
4
  before_enqueue do |job|
2✔
UNCOV
5
    project = Project.find(job.arguments.first[:project_id])
3✔
UNCOV
6
    FileInventoryRequest.create(user_id: job.arguments.first[:user_id], project_id: job.arguments.first[:project_id], job_id: @job_id, state: UserRequest::PENDING,
3✔
UNCOV
7
                                request_details: { project_title: project.title })
UNCOV
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
UNCOV
12
  before_perform do |job|
2✔
UNCOV
13
    project = Project.find(job.arguments.first[:project_id])
2✔
UNCOV
14
    inventory_request = FileInventoryRequest.find_by(user_id: job.arguments.first[:user_id], project_id: job.arguments.first[:project_id], job_id: @job_id)
2✔
UNCOV
15
    if inventory_request.blank?
2✔
UNCOV
16
      FileInventoryRequest.create(user_id: job.arguments.first[:user_id], project_id: job.arguments.first[:project_id], job_id: @job_id, state: UserRequest::PENDING,
2✔
UNCOV
17
                                  request_details: { project_title: project.title })
UNCOV
18
    end
UNCOV
19
  end
20

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

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

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

37
    # Update the job record as completed
UNCOV
38
    update_inventory_request(user_id: user.id, project: project, job_id: @job_id, filename: filename)
2✔
UNCOV
39
  rescue Mediaflux::SessionExpired => e
40
    # do not retry we can not continue if the session is expired
UNCOV
41
    fail_inventory_request(user_id: user.id, project: project, job_id: @job_id)
×
UNCOV
42
  end
43

UNCOV
44
  private
2✔
45

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

UNCOV
51
    def filename_for_export
2✔
UNCOV
52
      raise "Shared location is not configured" if Rails.configuration.mediaflux["shared_files_location"].blank?
2✔
UNCOV
53
      pathname = Pathname.new(Rails.configuration.mediaflux["shared_files_location"])
2✔
UNCOV
54
      pathname.join("#{job_id}.csv").to_s
2✔
UNCOV
55
    end
56

UNCOV
57
    def fail_inventory_request(user_id:, project:, job_id: )
2✔
UNCOV
58
      inventory_request = FileInventoryRequest.find_by(user_id: user_id, project_id: project.id, job_id: job_id)
×
UNCOV
59
      request_details = { project_title: project.title, error: "Mediaflux session expired" }
×
UNCOV
60
      inventory_request.update(state: UserRequest::FAILED, request_details: request_details,
×
UNCOV
61
                                completion_time: Time.current.in_time_zone("America/New_York"))
UNCOV
62
      inventory_request
×
UNCOV
63
    rescue ActiveRecord::StatementInvalid
UNCOV
64
      Rails.logger.info "Export - failing inventory request details for project #{project.id} job_id: #{job_id} failed, about to retry"
×
UNCOV
65
      ActiveRecord::Base.connection_pool.release_connection
×
UNCOV
66
      retry
×
UNCOV
67
    end
68

UNCOV
69
    def update_inventory_request(user_id:, project:, job_id:, filename: )
2✔
UNCOV
70
      Rails.logger.info "Export - updating inventory request details for project #{project.id}"
2✔
UNCOV
71
      inventory_request = FileInventoryRequest.find_by(user_id: user_id, project_id: project.id, job_id: job_id)
2✔
UNCOV
72
      request_details = { output_file: filename, project_title: project.title, file_size: File.size(filename) }
2✔
UNCOV
73
      inventory_request.update(state: UserRequest::COMPLETED, request_details: request_details,
2✔
UNCOV
74
                                completion_time: Time.current.in_time_zone("America/New_York"))
UNCOV
75
      Rails.logger.info "Export - updated inventory request details for project #{project.id}"
2✔
UNCOV
76
      inventory_request
2✔
UNCOV
77
    rescue ActiveRecord::StatementInvalid
UNCOV
78
      Rails.logger.info "Export - updating inventory request details for project #{project.id} failed, about to retry"
×
UNCOV
79
      ActiveRecord::Base.connection_pool.release_connection
×
UNCOV
80
      retry
×
UNCOV
81
    end
UNCOV
82
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