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

pulibrary / tigerdata-app / 8d70f2ab-acc5-4aab-b64b-743d66ddd2eb

29 Aug 2025 06:22PM UTC coverage: 87.983% (-0.1%) from 88.118%
8d70f2ab-acc5-4aab-b64b-743d66ddd2eb

Pull #1801

circleci

JaymeeH
Merge branch '1586-request-mailer' of https://github.com/pulibrary/tiger-data-app into 1586-request-mailer
Pull Request #1801: 1586 request mailer

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

1173 existing lines in 56 files now uncovered.

2482 of 2821 relevant lines covered (87.98%)

317.98 hits per line

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

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

21
  def perform(user_id:, project_id:, mediaflux_session:)
2✔
22
    project = Project.find(project_id)
12✔
23
    raise "Invalid project id #{project_id} for job #{job_id}" if project.nil?
12✔
24
    user = User.find(user_id)
12✔
25
    raise "Invalid user id #{user_id} for job #{job_id}" if user.nil?
11✔
26
    Rails.logger.debug inspect
11✔
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: })
11✔
30

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

37
    # Update the job record as completed
38
    update_inventory_request(user_id: user.id, project: project, job_id: @job_id, filename: filename)
11✔
39
  end
40

41
  private
2✔
42

43
    def mediaflux_session
2✔
44
      logon_request = Mediaflux::LogonRequest.new
×
45
      logon_request.session_token
×
46
    end
47

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

54
    def update_inventory_request(user_id:, project:, job_id:, filename: )
2✔
55
      Rails.logger.info "Export - updating inventory request details for project #{project.id}"
12✔
56
      inventory_request = FileInventoryRequest.find_by(user_id: user_id, project_id: project.id, job_id: job_id)
12✔
57
      request_details = { output_file: filename, project_title: project.title, file_size: File.size(filename) }
12✔
58
      inventory_request.update(state: UserRequest::COMPLETED, request_details: request_details,
12✔
59
                                completion_time: Time.current.in_time_zone("America/New_York"))
60
      Rails.logger.info "Export - updated inventory request details for project #{project.id}"
11✔
61
      inventory_request
11✔
62
    rescue ActiveRecord::StatementInvalid
UNCOV
63
      Rails.logger.info "Export - updating inventory request details for project #{project.id} failed, about to retry"
1✔
UNCOV
64
      ActiveRecord::Base.connection_pool.release_connection
1✔
UNCOV
65
      retry
1✔
66
    end
67
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