Class: DwcaCreateIndexJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/dwca_create_index_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(klass, sql_scope: nil) ⇒ Object

Parameters:

  • klass (String)

    the target class of the objects being re-indexed (CollectionObject, TODO: AssertedDistribution)

  • sql_scope (String) (defaults to: nil)

    a SQL string that when executed returns objects of klass



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/jobs/dwca_create_index_job.rb', line 8

def perform(klass, sql_scope: nil)
  errors = {}
  s =  klass.safe_constantize.from('(' + sql_scope + ') as ' + klass.tableize)
  s.find_each do |o|
    begin
      o.set_dwc_occurrence
    rescue RGeo::Error::InvalidGeometry => e
      puts Rainbow("Error [#{o.id}] bad geometry not written. #{e}").red.bold
      errors[o.to_global_id.to_s] = e
    end
  end

  errors
end