Class: DwcaCreateDownloadJob

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

Instance Method Summary collapse

Instance Method Details

#max_attemptsObject



4
5
6
# File 'app/jobs/dwca_create_download_job.rb', line 4

def max_attempts
  1
end

#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

Creates a DwC-A export and packages it into a Download.

Parameters:

  • download_id (Integer)

    The ID of the Download instance to package the export into.

  • core_scope (String, ActiveRecord::Relation) (defaults to: nil)

    Required. DwcOccurrence scope (SQL string or ActiveRecord::Relation).

  • extension_scopes (Hash) (defaults to: {biological_associations: nil, media: nil})

    Optional extensions to include:

    • :biological_associations [Hash] with keys :core_params and :collection_objects_query

    • :media [Hash] with keys :collection_objects (query string) and :field_occurrences (query string)

  • predicate_extensions (Hash) (defaults to: {})

    Predicate IDs to include:

    • :collection_object_predicate_id [Array<Integer>]

    • :collecting_event_predicate_id [Array<Integer>]

  • eml_data (Hash) (defaults to: {dataset: nil, additional_metadata: nil})

    EML metadata configuration:

    • :dataset [String] XML string for dataset metadata

    • :additional_metadata [String] XML string for additional metadata

  • taxonworks_extensions (Array<Symbol>) (defaults to: [])

    TaxonWorks-specific fields to export (e.g., [:otu_name, :elevation_precision]).

  • project_id (Integer) (defaults to: nil)

    Required. The project ID for scoping queries.

Raises:

  • (TaxonWorks::Error)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/jobs/dwca_create_download_job.rb', line 32

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::Occurrence::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