Class: Pageflow::FileImportJob
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- Pageflow::FileImportJob
- Defined in:
- app/jobs/pageflow/file_import_job.rb
Overview
Import the list of file(s), It includes fetching of the file data from its source and uploading the file to s3
Instance Method Summary collapse
- #perform(import_model_id, credentials) ⇒ Object
- #save_to_tempfile(data) ⇒ Object
- #upload_attachment(file_record, temp_file) ⇒ Object
Instance Method Details
#perform(import_model_id, credentials) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/jobs/pageflow/file_import_job.rb', line 10 def perform(import_model_id, credentials) import_model = FileImport.find(import_model_id) file_record = import_model.file = JSON.parse import_model. file_source = import_model.file_importer.download_file credentials, temp_file = save_to_tempfile(file_source) file_record, temp_file file_record.publish! ensure temp_file.delete end |
#save_to_tempfile(data) ⇒ Object
29 30 31 32 33 34 35 |
# File 'app/jobs/pageflow/file_import_job.rb', line 29 def save_to_tempfile(data) file = Tempfile.new('foo') file.binmode file.write(data) file.flush file end |
#upload_attachment(file_record, temp_file) ⇒ Object
22 23 24 25 26 27 |
# File 'app/jobs/pageflow/file_import_job.rb', line 22 def (file_record, temp_file) = file_record. .assign(temp_file) file_record.restore_attributes .flush_writes end |