Class: DwcaCreateChecklistDownloadJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/dwca_create_checklist_download_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(download_id, core_otu_scope_params: {}, extensions: [], accepted_name_mode: ::Export::Dwca::Checklist::Data::REPLACE_WITH_ACCEPTED_NAME, description_topics: [], project_id: nil) ⇒ Object

Parameters:

  • download_id (Integer)

    Download record ID

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

    OTU query parameters

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

    Extensions to include

  • accepted_name_mode (String) (defaults to: ::Export::Dwca::Checklist::Data::REPLACE_WITH_ACCEPTED_NAME)

    How to handle unaccepted names ('replace_with_accepted_name' or 'accepted_name_usage_id')

  • description_topics (Array<Integer>) (defaults to: [])

    Ordered list of topic IDs for description extension

  • project_id (Integer) (defaults to: nil)

    Project ID

Raises:

  • (TaxonWorks::Error)


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

def perform(download_id, core_otu_scope_params: {}, extensions: [], accepted_name_mode: ::Export::Dwca::Checklist::Data::REPLACE_WITH_ACCEPTED_NAME, description_topics: [], 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_otu_scope_params}" if project_id.nil?
  Current.project_id = project_id

  begin
    begin
      d = ::Export::Dwca::Checklist::Data.new(core_otu_scope_params:, extensions:, accepted_name_mode:, description_topics:)
      d.package_download(download)
    ensure
      d&.cleanup
    end
  rescue => ex
    ExceptionNotifier.notify_exception(ex, data: { download: download&.id&.to_s, project_id: } )
    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