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
- #queue_name ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(generic_file_id, directory, filename, user_key) ⇒ IngestLocalFileJob
Returns a new instance of 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
35 36 37 |
# File 'app/jobs/ingest_local_file_job.rb', line 35 def job_user User.batchuser end |
#queue_name ⇒ Object
4 5 6 |
# File 'app/jobs/ingest_local_file_job.rb', line 4 def queue_name :ingest end |
#run ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/jobs/ingest_local_file_job.rb', line 15 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) generic_file.label = File.basename(filename) generic_file.add_file(File.open(path), 'content', generic_file.label) generic_file.record_version_committer(user) generic_file.save! FileUtils.rm(path) Sufia.queue.push(ContentDepositEventJob.new(generic_file.pid, user_key)) # add message to user for downloaded file = "The file (#{File.basename(filename)}) was successfully deposited." job_user.(user, , 'Local file ingest') rescue => error job_user.(user, error., 'Local file ingest error') end |