Class: ActivateProjectJob

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

Instance Method Summary collapse

Instance Method Details

#perform(user:, project_id:) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/jobs/activate_project_job.rb', line 4

def perform(user:, project_id:)
  project = Project.find(project_id)
  raise "Invalid project id #{project_id} for job #{job_id}" if project.nil?
  #The id of the project in mediaflux is the collection id, and mediaflux id is what we refer to the collection id in rails
  collection_id = project.mediaflux_id

  # ACTIVATE THE PROJECT IF THE DOI IN RAILS AND MF MATCH
  project.activate!(collection_id: collection_id, current_user: user)

  project.reload
  return unless project.status != Project::ACTIVE_STATUS #CHECK IF PROJECT ACTIVATION WAS SUCCESSFUL
  activation_failure_msg = "Project with #{collection_id} failed to activate due to mismatched DOI's between rails and mediaflux"

  #SEND EMAIL
  mailer = TigerdataMailer.with(project_id: project.id, user:, activation_failure_msg:)
  message_delivery = mailer.project_activation
  message_delivery.deliver_later

  # NOTIFY HONEYBADGER
  honeybadger_context = {
    project_id: project.id,
    project_metadata: project.
  }
  Honeybadger.notify(activation_failure_msg, context: honeybadger_context)
end