Class: TrimWhitespaceRunner
- Defined in:
- backend/app/lib/job_runners/trim_whitespace_runner.rb
Instance Method Summary collapse
Methods inherited from JobRunner
#add_success_hook, #cancelation_signaler, #canceled?, for, #initialize, #parse_job_params_string, register_for_job_type, registered_job_types, registered_runner_for, #success!, #symbol_keys
Constructor Details
This class inherits a constructor from JobRunner
Instance Method Details
#run ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'backend/app/lib/job_runners/trim_whitespace_runner.rb', line 4 def run begin modified_records = [] RequestContext.open(:repo_id => @job.repo_id) do [Resource, ArchivalObject, Accession, DigitalObject, DigitalObjectComponent].each do |record_class| @job.write_output("Trimming whitespace from #{record_class} titles") count = 0 RequestContext.open(:current_username => @job.owner.username, :repo_id => @job.repo_id) do record_class.this_repo.extension(:pagination).each_page(25).each do |page_ds| page_ds.each do |r| if r[:title] && (trimmed = r[:title].strip) != r[:title] count += 1 # update through the jsonmodel to fire off callbacks, hooks etc. json = record_class.to_jsonmodel(r) json['title'] = trimmed record_class[r.id].update_from_json(json) modified_records << r.uri end end end end @job.write_output("#{count} records modified.") @job.write_output("================================") end end if modified_records.empty? @job.write_output("All done, no records modified.") else @job.write_output("All done, logging modified records.") end self.success! # just reuse JobCreated api for now... @job.record_created_uris(modified_records) rescue Exception => e @job.write_output(e.) @job.write_output(e.backtrace) raise e end end |