Class: BatchUpdateJob
- Inherits:
-
Object
- Object
- BatchUpdateJob
- Includes:
- Hydra::PermissionsQuery, Sufia::Messages
- Defined in:
- app/jobs/batch_update_job.rb
Instance Attribute Summary collapse
-
#batch_id ⇒ Object
Returns the value of attribute batch_id.
-
#denied ⇒ Object
Returns the value of attribute denied.
-
#file_attributes ⇒ Object
Returns the value of attribute file_attributes.
-
#login ⇒ Object
Returns the value of attribute login.
-
#saved ⇒ Object
Returns the value of attribute saved.
-
#title ⇒ Object
Returns the value of attribute title.
-
#visibility ⇒ Object
Returns the value of attribute visibility.
Attributes included from Sufia::Messages
Instance Method Summary collapse
-
#initialize(login, params) ⇒ BatchUpdateJob
constructor
A new instance of BatchUpdateJob.
- #queue_name ⇒ Object
- #run ⇒ Object
- #send_user_failure_message(user, batch) ⇒ Object
- #send_user_success_message(user, batch) ⇒ Object
- #update_file(gf, user) ⇒ Object
Methods included from Sufia::Messages
#failure_subject, #file_list, #link_to_file, #multiple_failure, #multiple_success, #single_failure, #single_success, #success_subject
Constructor Details
#initialize(login, params) ⇒ BatchUpdateJob
Returns a new instance of BatchUpdateJob.
11 12 13 14 15 16 17 18 19 |
# File 'app/jobs/batch_update_job.rb', line 11 def initialize(login, params) self.login = login self.title = params[:title] self.file_attributes = params[:generic_file] self.visibility = params[:visibility] self.batch_id = params[:id] self.saved = [] self.denied = [] end |
Instance Attribute Details
#batch_id ⇒ Object
Returns the value of attribute batch_id.
9 10 11 |
# File 'app/jobs/batch_update_job.rb', line 9 def batch_id @batch_id end |
#denied ⇒ Object
Returns the value of attribute denied.
9 10 11 |
# File 'app/jobs/batch_update_job.rb', line 9 def denied @denied end |
#file_attributes ⇒ Object
Returns the value of attribute file_attributes.
9 10 11 |
# File 'app/jobs/batch_update_job.rb', line 9 def file_attributes @file_attributes end |
#login ⇒ Object
Returns the value of attribute login.
9 10 11 |
# File 'app/jobs/batch_update_job.rb', line 9 def login @login end |
#saved ⇒ Object
Returns the value of attribute saved.
9 10 11 |
# File 'app/jobs/batch_update_job.rb', line 9 def saved @saved end |
#title ⇒ Object
Returns the value of attribute title.
9 10 11 |
# File 'app/jobs/batch_update_job.rb', line 9 def title @title end |
#visibility ⇒ Object
Returns the value of attribute visibility.
9 10 11 |
# File 'app/jobs/batch_update_job.rb', line 9 def visibility @visibility end |
Instance Method Details
#queue_name ⇒ Object
5 6 7 |
# File 'app/jobs/batch_update_job.rb', line 5 def queue_name :batch_update end |
#run ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/jobs/batch_update_job.rb', line 21 def run batch = Batch.find_or_create(self.batch_id) user = User.find_by_user_key(self.login) batch.generic_files.each do |gf| update_file(gf, user) end batch.update_attributes({status:["Complete"]}) if denied.empty? (user, batch) unless saved.empty? else (user, batch) end end |
#send_user_failure_message(user, batch) ⇒ Object
66 67 68 69 |
# File 'app/jobs/batch_update_job.rb', line 66 def user, batch = denied.count > 1 ? multiple_failure(batch.noid, denied) : single_failure(batch.noid, denied.first) User.batchuser.(user, , failure_subject, sanitize_text = false) end |
#send_user_success_message(user, batch) ⇒ Object
61 62 63 64 |
# File 'app/jobs/batch_update_job.rb', line 61 def user, batch = saved.count > 1 ? multiple_success(batch.noid, saved) : single_success(batch.noid, saved.first) User.batchuser.(user, , success_subject, sanitize_text = false) end |
#update_file(gf, user) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/jobs/batch_update_job.rb', line 36 def update_file(gf, user) unless user.can? :edit, gf ActiveFedora::Base.logger.error "User #{user.user_key} DENIED access to #{gf.pid}!" denied << gf return end gf.title = title[gf.pid] if title[gf.pid] rescue gf.label gf.attributes=file_attributes gf.visibility= visibility save_tries = 0 begin gf.save! rescue RSolr::Error::Http => error save_tries += 1 ActiveFedora::Base.logger.warn "BatchUpdateJob caught RSOLR error on #{gf.pid}: #{error.inspect}" # fail for good if the tries is greater than 3 raise error if save_tries >=3 sleep 0.01 retry end # Sufia.queue.push(ContentUpdateEventJob.new(gf.pid, login)) saved << gf end |