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

pulibrary / tigerdata-app / 1bbbf6c7-dbfb-464c-bd20-c3056db39fc5

06 Mar 2025 06:41PM UTC coverage: 83.757% (-0.5%) from 84.246%
1bbbf6c7-dbfb-464c-bd20-c3056db39fc5

push

circleci

web-flow
Rake task to run a FileInventoryJob from the command line (#1335)

* Temporary hack to use a non-CAS session when running the File Inventory Job and test if that causes the performance to slow down

* Allow file inventory to be run from a rake task. Allow user to pass the MF credentials to use

* Rubocop nitpicking

* Better prompt

4 of 4 branches covered (100.0%)

10 of 28 new or added lines in 3 files covered. (35.71%)

2408 of 2875 relevant lines covered (83.76%)

461.6 hits per line

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

15.15
/lib/tasks/file_inventory.rake
1
# frozen_string_literal: true
2

3
namespace :file_inventory do
1✔
4
  desc "Attaches a file to a file inventory job"
1✔
5
  task :attach_file, [:job_id, :filename] => [:environment] do |_, args|
1✔
6
    job_id = args[:job_id]
×
7
    filename = args[:filename]
×
8

9
    request = FileInventoryRequest.where(job_id: job_id).first
×
10
    raise "Job #{job_id} not found" if request.nil?
×
11
    raise "File #{filename} not found" unless File.exist?(filename)
×
12

13
    puts "Attaching file #{filename} to job #{job_id}"
×
14
    request.completion_time = Time.current.in_time_zone("America/New_York")
×
15
    request.state = "completed"
×
16
    request.request_details = { file_size: File.size(filename), output_file: filename, project_title: request.project.title }
×
17
    request.save!
×
18
  end
19

20
  desc "Runs a file inventory job (asks for the MediaFlux credentials to use)"
1✔
21
  task :run, [:project_id, :netid] => [:environment] do |_, args|
1✔
NEW
22
    project_id = args[:project_id]
×
NEW
23
    netid = args[:netid]
×
NEW
24
    project = Project.find(project_id)
×
NEW
25
    user = User.where(uid: netid).first
×
26

27
    # Lets the user enter the credentials to use (domain, username, password)
28
    # notice that the password is not displayed
NEW
29
    puts "Enter the credentials to connect to MediaFlux"
×
NEW
30
    puts "domain: "
×
NEW
31
    mf_domain = STDIN.gets.chomp
×
32

NEW
33
    puts "user: "
×
NEW
34
    mf_user = STDIN.gets.chomp
×
35

NEW
36
    puts "password: "
×
NEW
37
    mf_password = STDIN.getpass.chomp
×
38

39
    # Get a MediaFlux session for the credentials entered by the user
NEW
40
    logon_request = Mediaflux::LogonRequest.new(domain: mf_domain, user: mf_user, password: mf_password, identity_token: nil, token_type: nil)
×
NEW
41
    mediaflux_session = logon_request.session_token
×
NEW
42
    if logon_request.error?
×
NEW
43
      raise logon_request.response_error[:message]
×
44
    end
45

46
    # Schedule the file inventory job using the MediaFlux session we just adquired
NEW
47
    puts "Scheduling file inventory using credentials for: #{mf_domain}:#{mf_user}, session: #{mediaflux_session}"
×
NEW
48
    job_request = FileInventoryJob.perform_later(user_id: user.id, project_id: project.id, mediaflux_session: mediaflux_session)
×
NEW
49
    puts "Scheduled file inventory #{job_request.job_id} for project #{project.title} (#{project.id}) user: #{user.uid} (#{user.id}), session: #{mediaflux_session}"
×
50
  end
51
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