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 |
# 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 record_class.this_repo.each do |r| if r[:title] && (trimmed = r[:title].strip) != r[:title] count += 1 r.update(:title => trimmed) modified_records << r.uri 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 |