Class: DwcOccurrenceRefreshJob

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

Instance Method Summary collapse

Instance Method Details

#max_attemptsObject



8
9
10
# File 'app/jobs/dwc_occurrence_refresh_job.rb', line 8

def max_attempts
  2
end

#max_run_timeObject



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

def max_run_time
  2.hour
end

#perform(project_id: nil, user_id: nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/jobs/dwc_occurrence_refresh_job.rb', line 12

def perform(project_id: nil, user_id: nil)
  q = DwcOccurrence.where(project_id:, is_stale: true)
  q.all.find_each do |o|
    begin
      Current.user_id = user_id # Jobs are run in different threads, in theory.
      o.dwc_occurrence_object.send(:set_dwc_occurrence)
    rescue =>  ex
      ExceptionNotifier.notify_exception(
        ex,
        data: { project_id:, user_id:}
      )
      raise
    end
  end
  q.all.update_all(is_stale: nil)
end