Class: Aker::Factories::Job

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/aker/factories/job.rb

Overview

A job consists of an aker_job_id and materials (samples). Validates presence of aker_job_id and ensures that there is at least one material.

Constant Summary collapse

ATTRIBUTES =
%i[
  job_id
  job_uuid
  work_order_id
  aker_job_url
  product_name
  process_name
  process_uuid
  modules
  product_version
  product_uuid
  project_uuid
  project_name
  cost_code
  container
  materials
  comment
  desired_date
  data_release_uuid
  priority
].freeze
DEFAULT_ATTRIBUTES =
{ data_release_uuid: nil, materials: {} }.freeze
IGNORE_ATTRIBUTES =
%w[container_id num_of_rows num_of_cols].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Job

Returns a new instance of Job.


45
46
47
48
49
50
# File 'app/aker/factories/job.rb', line 45

def initialize(params = {})
  @container_params =
    params.to_h.with_indifferent_access[:container].reject { |k, _v| IGNORE_ATTRIBUTES.include?(k) }
  super(DEFAULT_ATTRIBUTES.merge(params))
  @aker_job_id = job_id
end

Instance Attribute Details

#aker_job_idObject (readonly)

Returns the value of attribute aker_job_id.


35
36
37
# File 'app/aker/factories/job.rb', line 35

def aker_job_id
  @aker_job_id
end

#modelObject (readonly)

Returns the value of attribute model.


35
36
37
# File 'app/aker/factories/job.rb', line 35

def model
  @model
end

Class Method Details

.create(params) ⇒ Object


41
42
43
# File 'app/aker/factories/job.rb', line 41

def self.create(params)
  new(params).create
end

Instance Method Details

#as_json(_options = {}) ⇒ Object


70
71
72
# File 'app/aker/factories/job.rb', line 70

def as_json(_options = {})
  { job: json_attributes }
end

#createObject

Persists a Job and all associated materials.


58
59
60
61
62
63
64
65
66
67
68
# File 'app/aker/factories/job.rb', line 58

def create
  return unless valid?

  @model =
    Aker::Job.create(
      aker_job_id: aker_job_id,
      job_uuid: job_uuid,
      samples: materials.map(&:create),
      aker_job_url: aker_job_url
    )
end

#materials=(materials) ⇒ Object


52
53
54
# File 'app/aker/factories/job.rb', line 52

def materials=(materials)
  @materials = build_materials(materials)
end

#studyObject


74
75
76
77
78
79
80
81
# File 'app/aker/factories/job.rb', line 74

def study
  return @study if @study

  uuid = Uuid.find_by(external_id: data_release_uuid)
  return nil unless uuid

  @study = Study.find(uuid.resource_id)
end