Class: IngestLocalFileJob
- Inherits:
-
Object
- Object
- IngestLocalFileJob
- Defined in:
- app/jobs/ingest_local_file_job.rb
Instance Attribute Summary collapse
-
#directory ⇒ Object
Returns the value of attribute directory.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#generic_file_id ⇒ Object
Returns the value of attribute generic_file_id.
-
#user_key ⇒ Object
Returns the value of attribute user_key.
Instance Method Summary collapse
-
#initialize(generic_file_id, directory, filename, user_key) ⇒ IngestLocalFileJob
constructor
A new instance of IngestLocalFileJob.
- #job_user ⇒ Object
- #mime_type(file_name) ⇒ Object
- #queue_name ⇒ Object
-
#run ⇒ Object
TODO: this should use Actor#create_content.
Constructor Details
#initialize(generic_file_id, directory, filename, user_key) ⇒ IngestLocalFileJob
8 9 10 11 12 13 |
# File 'app/jobs/ingest_local_file_job.rb', line 8 def initialize(generic_file_id, directory, filename, user_key) self.generic_file_id = generic_file_id self.directory = directory self.filename = filename self.user_key = user_key end |
Instance Attribute Details
#directory ⇒ Object
Returns the value of attribute directory.
2 3 4 |
# File 'app/jobs/ingest_local_file_job.rb', line 2 def directory @directory end |
#filename ⇒ Object
Returns the value of attribute filename.
2 3 4 |
# File 'app/jobs/ingest_local_file_job.rb', line 2 def filename @filename end |
#generic_file_id ⇒ Object
Returns the value of attribute generic_file_id.
2 3 4 |
# File 'app/jobs/ingest_local_file_job.rb', line 2 def generic_file_id @generic_file_id end |
#user_key ⇒ Object
Returns the value of attribute user_key.
2 3 4 |
# File 'app/jobs/ingest_local_file_job.rb', line 2 def user_key @user_key end |
Instance Method Details
#job_user ⇒ Object
38 39 40 |
# File 'app/jobs/ingest_local_file_job.rb', line 38 def job_user User.batchuser end |
#mime_type(file_name) ⇒ Object
42 43 44 45 |
# File 'app/jobs/ingest_local_file_job.rb', line 42 def mime_type(file_name) mime_types = MIME::Types.of(file_name) mime_types.empty? ? "application/octet-stream" : mime_types.first.content_type end |
#queue_name ⇒ Object
4 5 6 |
# File 'app/jobs/ingest_local_file_job.rb', line 4 def queue_name :ingest end |
#run ⇒ Object
TODO: this should use Actor#create_content
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/jobs/ingest_local_file_job.rb', line 16 def run user = User.find_by_user_key(user_key) raise "Unable to find user for #{user_key}" unless user generic_file = GenericFile.find(generic_file_id) path = File.join(directory, filename) actor = Sufia::GenericFile::Actor.new(generic_file, user) if actor.create_content(File.open(path), filename, 'content', mime_type(filename)) FileUtils.rm(path) Sufia.queue.push(ContentDepositEventJob.new(generic_file.id, user_key)) = "The file (#{File.basename(filename)}) was successfully deposited." subject = 'Local file ingest' else = "There was a problem depositing #{File.basename(filename)}. Please contact a system admin." subject = 'Local file ingest error' end job_user.(user, , subject) end |