Class: DwcaCreateDownloadJob

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

Instance Method Summary collapse

Instance Method Details

#perform(download_id, core_scope: nil, extension_scopes: {biological_associations: nil, media: nil}, predicate_extensions: {}, eml_data: {dataset: nil, additional_metadata: nil}, taxonworks_extensions: [], project_id: nil) ⇒ Object

take a download, and a list of scopes, and save the result to the download, that’s all

Parameters:

  • download (a Download instance)
  • core_scope (String, ActiveRecord::Relation) (defaults to: nil)

    String of SQL generated from the scope SQL must return a list of DwcOccurrence records

Raises:

  • (TaxonWorks::Error)


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
# File 'app/jobs/dwca_create_download_job.rb', line 9

def perform(download_id, core_scope: nil, extension_scopes: {biological_associations: nil, media: nil}, predicate_extensions: {}, eml_data: {dataset: nil, additional_metadata: nil}, taxonworks_extensions: [],
project_id: nil)
  # Raise and fail without notifying if our download was deleted before we run.
  download = Download.find(download_id)
  # Filter queries will fail in unexpected ways without project_id set as
  # expected!
  raise TaxonWorks::Error, "Project_id not set! #{core_scope}" if project_id.nil?
  Current.project_id = project_id

  begin
    begin
      d = ::Export::Dwca::Data.new(core_scope:, predicate_extensions:, extension_scopes:, taxonworks_extensions:, eml_data:)
      d.package_download(download)
    ensure
      d&.cleanup
    end
  rescue => ex
    ExceptionNotifier.notify_exception(ex, data: { download: download&.id&.to_s } )
    raise
  end

  # The zipfile has been moved to its download location, but the db download
  # could have been deleted at any time during our processing (in a
  # different thread), so see if we need to do some cleanup.
  if !Download.find_by(id: download.id)
    download.delete_file # doesn't raise if file is already gone
    raise TaxonWorks::Error, "Complete download build aborted: download '#{download.id}' no longer exists."
    return
  end
end