Skip to content

Commit

Permalink
Isolate data is now imported in teh background.
Browse files Browse the repository at this point in the history
  • Loading branch information
SarahW91 committed Mar 12, 2022
1 parent e862bc8 commit f739c98
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion app/controllers/isolates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ def import
file = params[:file]

if file
IsolateImporter.perform_async(params[:file], current_user.default_project_id)
file_name = file.original_filename
path = File.join("tmp", file_name)
File.open(path, "wb") { |f| f.write(file.read) }

IsolateImporter.perform_async(path, current_user.default_project_id)
redirect_to isolates_path,
notice: "Isolate and specimen data will be imported in the background."
else
Expand Down
4 changes: 2 additions & 2 deletions app/models/isolate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class Isolate < ApplicationRecord
scope :recent, -> { where('isolates.updated_at > ?', 1.hours.ago) }
scope :no_controls, -> { where(negative_control: false) }

def self.import(file, project_id)
spreadsheet = Isolate.open_spreadsheet(file)
def self.import(file_path, project_id)
spreadsheet = Roo::CSV.new(file_path)
header = spreadsheet.row(1)

(2..spreadsheet.last_row).each do |i|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class IsolateImporter
include Sidekiq::Worker

def perform(file, project_id)
Isolate.import(file, project_id)
def perform(file_path, project_id)
Isolate.import(file_path, project_id)
end
end

0 comments on commit f739c98

Please sign in to comment.