Class: BulkCsvParser::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/bulk_csv_parser/storage.rb

Overview

Moves the uploaded CSV from the machine that received the HTTP request to wherever ImportJob actually executes -- which, in production, is very often a separate worker box (Sidekiq/Resque/GoodJob fleet) with no access to the web server's local disk or its request-scoped tempfile.

store is called on the web process and returns a small, serializable "reference" (a String) that's safe to pass as an ActiveJob argument. fetch is called on the worker process and turns that reference back into a local file it can stream with CSV.foreach. cleanup removes the persisted copy once the job is done with it.

Defined Under Namespace

Modules: ActiveStorageAdapter, LocalAdapter Classes: UnknownAdapterError

Class Method Summary collapse

Class Method Details

.cleanup(reference) ⇒ Object



30
31
32
# File 'lib/bulk_csv_parser/storage.rb', line 30

def cleanup(reference)
  adapter.cleanup(reference)
end

.fetch(reference) ⇒ Object

Returns an object responding to #path; call #cleanup_local(result) on it when done reading, if it responds to that (see Local::Handle).



26
27
28
# File 'lib/bulk_csv_parser/storage.rb', line 26

def fetch(reference)
  adapter.fetch(reference)
end

.store(file) ⇒ Object



20
21
22
# File 'lib/bulk_csv_parser/storage.rb', line 20

def store(file)
  adapter.store(file)
end