Class: SampleAccessioningJob

Inherits:
Struct
  • Object
show all
Defined in:
app/jobs/sample_accessioning_job.rb

Overview

Sends sample data to the ENA or EGA in order to generate an accession number Records the generated accession number on the sample Records the statuses and response from the failed attempts in the accession statuses

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#accessionableObject

Returns the value of attribute accessionable

Returns:

  • (Object)

    the current value of accessionable



12
13
14
# File 'app/jobs/sample_accessioning_job.rb', line 12

def accessionable
  @accessionable
end

#event_userObject

Returns the value of attribute event_user

Returns:

  • (Object)

    the current value of event_user



12
13
14
# File 'app/jobs/sample_accessioning_job.rb', line 12

def event_user
  @event_user
end

Class Method Details

.contact_userObject

Retrieve the contact user for accessioning submissions



15
16
17
# File 'app/jobs/sample_accessioning_job.rb', line 15

def self.contact_user
  User.find_by(api_key: configatron.accession_local_key)
end

Instance Method Details

#before(_job) ⇒ Object

Called before the job is run



67
68
69
# File 'app/jobs/sample_accessioning_job.rb', line 67

def before(_job)
  progress_accession_status
end

#enqueue(_job) ⇒ Object

Called when the job is initially enqueued



62
63
64
# File 'app/jobs/sample_accessioning_job.rb', line 62

def enqueue(_job)
  create_queued_accession_status
end

#failure(_job) ⇒ Object

Called after the job has failed max_attempts times



77
78
79
# File 'app/jobs/sample_accessioning_job.rb', line 77

def failure(_job)
  abort_accession_status
end

#max_attemptsObject



36
37
38
39
# File 'app/jobs/sample_accessioning_job.rb', line 36

def max_attempts
  # When changing, also update attempt description text in app/views/samples/_accession_statuses.html.erb
  3
end

#performObject



19
20
21
22
23
24
25
26
27
28
29
# File 'app/jobs/sample_accessioning_job.rb', line 19

def perform
  contact_user = self.class.contact_user
  submission = Accession::Submission.new(contact_user, accessionable)
  submission.submit_and_update_accession_number(event_user)
rescue StandardError => e
  handle_job_error(e, submission)

  # Raising an error to Delayed::Job will signal that the job should be retried at a later time
  job_failed_message = "#{e.class}: #{e.message}"
  raise JobFailed, job_failed_message
end

#queue_nameObject



41
42
43
# File 'app/jobs/sample_accessioning_job.rb', line 41

def queue_name
  'sample_accessioning'
end

#reschedule_at(current_time, _attempts) ⇒ Object



31
32
33
34
# File 'app/jobs/sample_accessioning_job.rb', line 31

def reschedule_at(current_time, _attempts)
  # When changing, also update attempt description text in app/views/samples/_accession_statuses.html.erb
  current_time + 1.day
end

#success(_job) ⇒ Object

Called after the job has completed successfully



72
73
74
# File 'app/jobs/sample_accessioning_job.rb', line 72

def success(_job)
  succeed_accession_status
end